<!-- HTML header for doxygen 1.8.8-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <!-- For Mobile Devices -->
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
        <meta name="generator" content="Doxygen 1.8.18"/>
        <script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
        <title>HElib: /HElib/include/helib/Context.h Source File</title>
        <!--<link href="tabs.css" rel="stylesheet" type="text/css"/>-->
        <script type="text/javascript" src="dynsections.js"></script>
        <link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
        <link href="doxygen.css" rel="stylesheet" type="text/css" />
        <link href="customdoxygen.css" rel="stylesheet" type="text/css"/>
        <link href='https://fonts.googleapis.com/css?family=Roboto+Slab' rel='stylesheet' type='text/css'>
		<link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:ital,wght@0,100;1,700&family=Merriweather&family=Merriweather+Sans&family=Open+Sans&family=Poppins:ital@1&family=Roboto:ital,wght@0,400;1,300;1,900&display=swap" rel="stylesheet"> 
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
        <link href="jquery.smartmenus.bootstrap.css" rel="stylesheet">
        <script type="text/javascript" src="jquery.smartmenus.js"></script>
        <!-- SmartMenus jQuery Bootstrap Addon -->
        <script type="text/javascript" src="jquery.smartmenus.bootstrap.js"></script>
        <!-- SmartMenus jQuery plugin -->
    </head>
    <body style="font-family: 'Merriweather', serif;">
        <nav class="navbar navbar-default" role="navigation">
            <div class="container">
                <div class="navbar-header">
                    <a class="navbar-brand">HElib Implementing Homomorphic Encryption</a>
                </div>
            </div>
        </nav>
        <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
            <div class="content" id="content">
                <div class="container">
                    <div class="row">
                        <div class="col-sm-12 panel " style="padding-bottom: 15px;">
                            <div style="margin-bottom: 15px;">
<!-- end header part -->
<!-- Generated by Doxygen 1.8.18 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_d44c64559bbebec7f509842c48db8b23.html">include</a></li><li class="navelem"><a class="el" href="dir_d0c4ae63660968bf6b1c77a1e8aecf95.html">helib</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">Context.h</div>  </div>
</div><!--header-->
<div class="contents">
<a href="_context_8h.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="comment">/* Copyright (C) 2012-2020 IBM Corp.</span></div>
<div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="comment"> * This program is Licensed under the Apache License, Version 2.0</span></div>
<div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="comment"> * (the &quot;License&quot;); you may not use this file except in compliance</span></div>
<div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="comment"> * with the License. You may obtain a copy of the License at</span></div>
<div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;<span class="comment"> *   http://www.apache.org/licenses/LICENSE-2.0</span></div>
<div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<span class="comment"> * Unless required by applicable law or agreed to in writing, software</span></div>
<div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;<span class="comment"> * distributed under the License is distributed on an &quot;AS IS&quot; BASIS,</span></div>
<div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;<span class="comment"> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span></div>
<div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;<span class="comment"> * See the License for the specific language governing permissions and</span></div>
<div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;<span class="comment"> * limitations under the License. See accompanying LICENSE file.</span></div>
<div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;<span class="preprocessor">#ifndef HELIB_CONTEXT_H</span></div>
<div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;<span class="preprocessor">#define HELIB_CONTEXT_H</span></div>
<div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160; </div>
<div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;<span class="preprocessor">#include &lt;<a class="code" href="_p_algebra_8h.html">helib/PAlgebra.h</a>&gt;</span></div>
<div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;<span class="preprocessor">#include &lt;<a class="code" href="_c_modulus_8h.html">helib/CModulus.h</a>&gt;</span></div>
<div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;<span class="preprocessor">#include &lt;<a class="code" href="_index_set_8h.html">helib/IndexSet.h</a>&gt;</span></div>
<div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;<span class="preprocessor">#include &lt;<a class="code" href="recryption_8h.html">helib/recryption.h</a>&gt;</span></div>
<div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;<span class="preprocessor">#include &lt;<a class="code" href="prime_chain_8h.html">helib/primeChain.h</a>&gt;</span></div>
<div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;<span class="preprocessor">#include &lt;<a class="code" href="powerful_8h.html">helib/powerful.h</a>&gt;</span></div>
<div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;<span class="preprocessor">#include &lt;<a class="code" href="api_attributes_8h.html">helib/apiAttributes.h</a>&gt;</span></div>
<div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160; </div>
<div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;<span class="preprocessor">#include &lt;NTL/Lazy.h&gt;</span></div>
<div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160; </div>
<div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;<span class="keyword">namespace </span><a class="code" href="namespacehelib.html">helib</a> {</div>
<div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160; </div>
<div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;<span class="keywordtype">long</span> <a class="code" href="namespacehelib.html#abbf9f5de032fca82af2ce94a97041bc6">FindM</a>(<span class="keywordtype">long</span> k,</div>
<div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;           <span class="keywordtype">long</span> nBits,</div>
<div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;           <span class="keywordtype">long</span> c,</div>
<div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;           <span class="keywordtype">long</span> p,</div>
<div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;           <span class="keywordtype">long</span> d,</div>
<div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;           <span class="keywordtype">long</span> s,</div>
<div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;           <span class="keywordtype">long</span> chosen_m,</div>
<div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;           <span class="keywordtype">bool</span> <a class="code" href="_test__approx_nums_8cpp.html#ab3f078684998b83967d507d0f453f454">verbose</a> = <span class="keyword">false</span>);</div>
<div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160; </div>
<div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160;<span class="keyword">class </span>EncryptedArray;</div>
<div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;<span class="keyword">struct </span>PolyModRing;</div>
<div class="line"><a name="l00057"></a><span class="lineno"><a class="line" href="classhelib_1_1_context.html">   57</a></span>&#160;<span class="keyword">class </span><a class="code" href="classhelib_1_1_context.html">Context</a></div>
<div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;{</div>
<div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160;  std::vector&lt;Cmodulus&gt; moduli; <span class="comment">// Cmodulus objects for the different primes</span></div>
<div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;  <span class="comment">// This is private since the implementation assumes that the list of</span></div>
<div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;  <span class="comment">// primes only grows and no prime is ever modified or removed.</span></div>
<div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160; </div>
<div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;<span class="keyword">public</span>:</div>
<div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;  <span class="comment">// Context is meant for convenience, not encapsulation: Most data</span></div>
<div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;  <span class="comment">// members are public and can be initialized by the application program.</span></div>
<div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160; </div>
<div class="line"><a name="l00068"></a><span class="lineno"><a class="line" href="classhelib_1_1_context.html#ab261446cf0a635a7bf1edf081df48d81">   68</a></span>&#160;  <a class="code" href="classhelib_1_1_p_algebra.html">PAlgebra</a> <a class="code" href="classhelib_1_1_context.html#ab261446cf0a635a7bf1edf081df48d81">zMStar</a>;</div>
<div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160; </div>
<div class="line"><a name="l00071"></a><span class="lineno"><a class="line" href="classhelib_1_1_context.html#a9a8689e8a591a15fdf4f1b5eb7b0b80c">   71</a></span>&#160;  <a class="code" href="classhelib_1_1_p_algebra_mod.html">PAlgebraMod</a> <a class="code" href="classhelib_1_1_context.html#a9a8689e8a591a15fdf4f1b5eb7b0b80c">alMod</a>;</div>
<div class="line"><a name="l00072"></a><span class="lineno">   72</span>&#160; </div>
<div class="line"><a name="l00074"></a><span class="lineno"><a class="line" href="classhelib_1_1_context.html#a8319e609dbde819ac81130b035711fee">   74</a></span>&#160;  std::shared_ptr&lt;const EncryptedArray&gt; <a class="code" href="classhelib_1_1_context.html#a8319e609dbde819ac81130b035711fee">ea</a>;</div>
<div class="line"><a name="l00075"></a><span class="lineno">   75</span>&#160; </div>
<div class="line"><a name="l00076"></a><span class="lineno"><a class="line" href="classhelib_1_1_context.html#a26f5e8b08576bf2ab4632bc8234243e2">   76</a></span>&#160;  std::shared_ptr&lt;const PowerfulDCRT&gt; <a class="code" href="classhelib_1_1_context.html#a26f5e8b08576bf2ab4632bc8234243e2">pwfl_converter</a>;</div>
<div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160; </div>
<div class="line"><a name="l00082"></a><span class="lineno"><a class="line" href="classhelib_1_1_context.html#a1a9dbcc75c6cf5116b8114dccc1f1ab7">   82</a></span>&#160;  std::shared_ptr&lt;PolyModRing&gt; <a class="code" href="classhelib_1_1_context.html#a1a9dbcc75c6cf5116b8114dccc1f1ab7">slotRing</a>;</div>
<div class="line"><a name="l00083"></a><span class="lineno">   83</span>&#160; </div>
<div class="line"><a name="l00085"></a><span class="lineno"><a class="line" href="classhelib_1_1_context.html#ad2eaf7ce504e725b8e6be631ff276efc">   85</a></span>&#160;  NTL::xdouble <a class="code" href="classhelib_1_1_context.html#ad2eaf7ce504e725b8e6be631ff276efc">stdev</a>;</div>
<div class="line"><a name="l00086"></a><span class="lineno">   86</span>&#160; </div>
<div class="line"><a name="l00087"></a><span class="lineno">   87</span>&#160;  <span class="comment">//======================= high probability bounds ================</span></div>
<div class="line"><a name="l00088"></a><span class="lineno"><a class="line" href="classhelib_1_1_context.html#a86b3d6e90031da9bc9cef6f46e9e9bda">   88</a></span>&#160;  <span class="keywordtype">double</span> <a class="code" href="classhelib_1_1_context.html#a86b3d6e90031da9bc9cef6f46e9e9bda">scale</a>; <span class="comment">// default = 10</span></div>
<div class="line"><a name="l00089"></a><span class="lineno">   89</span>&#160; </div>
<div class="line"><a name="l00097"></a><span class="lineno">   97</span>&#160; </div>
<div class="line"><a name="l00107"></a><span class="lineno">  107</span>&#160; </div>
<div class="line"><a name="l00108"></a><span class="lineno">  108</span>&#160;  <span class="comment">//=======================================</span></div>
<div class="line"><a name="l00109"></a><span class="lineno">  109</span>&#160; </div>
<div class="line"><a name="l00116"></a><span class="lineno">  116</span>&#160; </div>
<div class="line"><a name="l00117"></a><span class="lineno">  117</span>&#160;  <span class="comment">// NOTE: this is a bit heuristic: we assume that if we evaluate</span></div>
<div class="line"><a name="l00118"></a><span class="lineno">  118</span>&#160;  <span class="comment">// f at a primitive root of unity, then we get something that well</span></div>
<div class="line"><a name="l00119"></a><span class="lineno">  119</span>&#160;  <span class="comment">// approximates a normal random variable with the same variance,</span></div>
<div class="line"><a name="l00120"></a><span class="lineno">  120</span>&#160;  <span class="comment">// which is equal to the sum of the variances of the individual</span></div>
<div class="line"><a name="l00121"></a><span class="lineno">  121</span>&#160;  <span class="comment">// f_i&#39;s, which is (2*magBound)^2/12 = magBound^2/3.</span></div>
<div class="line"><a name="l00122"></a><span class="lineno">  122</span>&#160;  <span class="comment">// We then multiply the sqrt of the variance by scale to get</span></div>
<div class="line"><a name="l00123"></a><span class="lineno">  123</span>&#160;  <span class="comment">// the high probability bound.</span></div>
<div class="line"><a name="l00124"></a><span class="lineno">  124</span>&#160; </div>
<div class="line"><a name="l00125"></a><span class="lineno"><a class="line" href="classhelib_1_1_context.html#ab79e1f941d6043131a14404c68bf538c">  125</a></span>&#160;  <span class="keywordtype">double</span> <a class="code" href="classhelib_1_1_context.html#ab79e1f941d6043131a14404c68bf538c">noiseBoundForUniform</a>(<span class="keywordtype">double</span> magBound, <span class="keywordtype">long</span> degBound)<span class="keyword"> const</span></div>
<div class="line"><a name="l00126"></a><span class="lineno">  126</span>&#160;<span class="keyword">  </span>{</div>
<div class="line"><a name="l00127"></a><span class="lineno">  127</span>&#160;    <span class="keywordflow">return</span> <a class="code" href="classhelib_1_1_context.html#a86b3d6e90031da9bc9cef6f46e9e9bda">scale</a> * std::sqrt(<span class="keywordtype">double</span>(degBound) / 3.0) * magBound;</div>
<div class="line"><a name="l00128"></a><span class="lineno">  128</span>&#160;  }</div>
<div class="line"><a name="l00129"></a><span class="lineno">  129</span>&#160; </div>
<div class="line"><a name="l00130"></a><span class="lineno"><a class="line" href="classhelib_1_1_context.html#ab25e83e61a64ed721a1b710a3b2df82d">  130</a></span>&#160;  NTL::xdouble <a class="code" href="classhelib_1_1_context.html#ab25e83e61a64ed721a1b710a3b2df82d">noiseBoundForUniform</a>(NTL::xdouble magBound, <span class="keywordtype">long</span> degBound)<span class="keyword"> const</span></div>
<div class="line"><a name="l00131"></a><span class="lineno">  131</span>&#160;<span class="keyword">  </span>{</div>
<div class="line"><a name="l00132"></a><span class="lineno">  132</span>&#160;    <span class="keywordflow">return</span> <a class="code" href="classhelib_1_1_context.html#a86b3d6e90031da9bc9cef6f46e9e9bda">scale</a> * std::sqrt(<span class="keywordtype">double</span>(degBound) / 3.0) * magBound;</div>
<div class="line"><a name="l00133"></a><span class="lineno">  133</span>&#160;  }</div>
<div class="line"><a name="l00134"></a><span class="lineno">  134</span>&#160; </div>
<div class="line"><a name="l00135"></a><span class="lineno">  135</span>&#160;  <span class="comment">//=======================================</span></div>
<div class="line"><a name="l00136"></a><span class="lineno">  136</span>&#160; </div>
<div class="line"><a name="l00143"></a><span class="lineno">  143</span>&#160; </div>
<div class="line"><a name="l00144"></a><span class="lineno">  144</span>&#160;  <span class="comment">// NOTE: for odd modulus, this means each f_i is uniformly distributed</span></div>
<div class="line"><a name="l00145"></a><span class="lineno">  145</span>&#160;  <span class="comment">// over { -floor(modulus/2), ..., floor(modulus/2) }.</span></div>
<div class="line"><a name="l00146"></a><span class="lineno">  146</span>&#160;  <span class="comment">// For even modulus, this means each f_i is uniformly distributed</span></div>
<div class="line"><a name="l00147"></a><span class="lineno">  147</span>&#160;  <span class="comment">// over { modulus/2, ..., modulus/2 }, except that the two endpoints</span></div>
<div class="line"><a name="l00148"></a><span class="lineno">  148</span>&#160;  <span class="comment">// (which represent the same residue class) occur with half the</span></div>
<div class="line"><a name="l00149"></a><span class="lineno">  149</span>&#160;  <span class="comment">// probability of the others.</span></div>
<div class="line"><a name="l00150"></a><span class="lineno">  150</span>&#160; </div>
<div class="line"><a name="l00151"></a><span class="lineno">  151</span>&#160;  <span class="comment">// NOTE: this is a bit heuristic: we assume that if we evaluate</span></div>
<div class="line"><a name="l00152"></a><span class="lineno">  152</span>&#160;  <span class="comment">// f at a primitive root of unity, then we get something that well</span></div>
<div class="line"><a name="l00153"></a><span class="lineno">  153</span>&#160;  <span class="comment">// approximates a normal random variable with the same variance,</span></div>
<div class="line"><a name="l00154"></a><span class="lineno">  154</span>&#160;  <span class="comment">// which is equal to the sum of the variances of the individual</span></div>
<div class="line"><a name="l00155"></a><span class="lineno">  155</span>&#160;  <span class="comment">// f_i&#39;s, which is (modulus)^2/12 + 1/6 for even modulus,</span></div>
<div class="line"><a name="l00156"></a><span class="lineno">  156</span>&#160;  <span class="comment">// and is at most (modulus^2)/12 for odd modulus.</span></div>
<div class="line"><a name="l00157"></a><span class="lineno">  157</span>&#160;  <span class="comment">// We then multiply the sqrt of the variance by scale to get</span></div>
<div class="line"><a name="l00158"></a><span class="lineno">  158</span>&#160;  <span class="comment">// the high probability bound.</span></div>
<div class="line"><a name="l00159"></a><span class="lineno">  159</span>&#160; </div>
<div class="line"><a name="l00160"></a><span class="lineno">  160</span>&#160;  <span class="comment">// NOTE: this is slightly more accurate that just calling</span></div>
<div class="line"><a name="l00161"></a><span class="lineno">  161</span>&#160;  <span class="comment">// noiseBoundForUniform with magBound=modulus/2.</span></div>
<div class="line"><a name="l00162"></a><span class="lineno">  162</span>&#160; </div>
<div class="line"><a name="l00163"></a><span class="lineno"><a class="line" href="classhelib_1_1_context.html#a93ce4564b2ec97c85c50e732c04a1b22">  163</a></span>&#160;  <span class="keywordtype">double</span> <a class="code" href="classhelib_1_1_context.html#a93ce4564b2ec97c85c50e732c04a1b22">noiseBoundForMod</a>(<span class="keywordtype">long</span> modulus, <span class="keywordtype">long</span> degBound)<span class="keyword"> const</span></div>
<div class="line"><a name="l00164"></a><span class="lineno">  164</span>&#160;<span class="keyword">  </span>{</div>
<div class="line"><a name="l00165"></a><span class="lineno">  165</span>&#160;    <span class="keywordtype">double</span> var = <a class="code" href="namespacehelib.html#ad92538fab792f75e009a2330c365637d">fsquare</a>(modulus) / 12.0;</div>
<div class="line"><a name="l00166"></a><span class="lineno">  166</span>&#160;    <span class="keywordflow">if</span> (modulus % 2 == 0)</div>
<div class="line"><a name="l00167"></a><span class="lineno">  167</span>&#160;      var += 1.0 / 6.0;</div>
<div class="line"><a name="l00168"></a><span class="lineno">  168</span>&#160; </div>
<div class="line"><a name="l00169"></a><span class="lineno">  169</span>&#160;    <span class="keywordflow">return</span> <a class="code" href="classhelib_1_1_context.html#a86b3d6e90031da9bc9cef6f46e9e9bda">scale</a> * std::sqrt(degBound * var);</div>
<div class="line"><a name="l00170"></a><span class="lineno">  170</span>&#160;  }</div>
<div class="line"><a name="l00171"></a><span class="lineno">  171</span>&#160; </div>
<div class="line"><a name="l00172"></a><span class="lineno">  172</span>&#160;  <span class="comment">//=======================================</span></div>
<div class="line"><a name="l00173"></a><span class="lineno">  173</span>&#160; </div>
<div class="line"><a name="l00180"></a><span class="lineno">  180</span>&#160; </div>
<div class="line"><a name="l00181"></a><span class="lineno">  181</span>&#160;  <span class="comment">// NOTE: if we evaluate f at a primitive root of unity,</span></div>
<div class="line"><a name="l00182"></a><span class="lineno">  182</span>&#160;  <span class="comment">// then we get a normal random variable variance degBound * sigma^2.</span></div>
<div class="line"><a name="l00183"></a><span class="lineno">  183</span>&#160;  <span class="comment">// We then multiply the sqrt of the variance by scale to get</span></div>
<div class="line"><a name="l00184"></a><span class="lineno">  184</span>&#160;  <span class="comment">// the high probability bound.</span></div>
<div class="line"><a name="l00185"></a><span class="lineno">  185</span>&#160; </div>
<div class="line"><a name="l00186"></a><span class="lineno"><a class="line" href="classhelib_1_1_context.html#ac2b4477cbc59e744b735544b60bb4f87">  186</a></span>&#160;  <span class="keywordtype">double</span> <a class="code" href="classhelib_1_1_context.html#ac2b4477cbc59e744b735544b60bb4f87">noiseBoundForGaussian</a>(<span class="keywordtype">double</span> sigma, <span class="keywordtype">long</span> degBound)<span class="keyword"> const</span></div>
<div class="line"><a name="l00187"></a><span class="lineno">  187</span>&#160;<span class="keyword">  </span>{</div>
<div class="line"><a name="l00188"></a><span class="lineno">  188</span>&#160;    <span class="keywordflow">return</span> <a class="code" href="classhelib_1_1_context.html#a86b3d6e90031da9bc9cef6f46e9e9bda">scale</a> * std::sqrt(<span class="keywordtype">double</span>(degBound)) * sigma;</div>
<div class="line"><a name="l00189"></a><span class="lineno">  189</span>&#160;  }</div>
<div class="line"><a name="l00190"></a><span class="lineno">  190</span>&#160; </div>
<div class="line"><a name="l00191"></a><span class="lineno">  191</span>&#160;  <span class="comment">//=======================================</span></div>
<div class="line"><a name="l00192"></a><span class="lineno">  192</span>&#160; </div>
<div class="line"><a name="l00199"></a><span class="lineno">  199</span>&#160; </div>
<div class="line"><a name="l00200"></a><span class="lineno">  200</span>&#160;  <span class="comment">// NOTE: this is a bit heuristic: we assume that if we evaluate</span></div>
<div class="line"><a name="l00201"></a><span class="lineno">  201</span>&#160;  <span class="comment">// f at a primitive root of unity, then we get something that</span></div>
<div class="line"><a name="l00202"></a><span class="lineno">  202</span>&#160;  <span class="comment">// well approximates a normal random variable with the same variance,</span></div>
<div class="line"><a name="l00203"></a><span class="lineno">  203</span>&#160;  <span class="comment">// which is equal to the sum of the individual variances,</span></div>
<div class="line"><a name="l00204"></a><span class="lineno">  204</span>&#160;  <span class="comment">// which is degBound*prob.</span></div>
<div class="line"><a name="l00205"></a><span class="lineno">  205</span>&#160;  <span class="comment">// We then multiply the sqrt of the variance by scale to get</span></div>
<div class="line"><a name="l00206"></a><span class="lineno">  206</span>&#160;  <span class="comment">// the high probability bound.</span></div>
<div class="line"><a name="l00207"></a><span class="lineno">  207</span>&#160; </div>
<div class="line"><a name="l00208"></a><span class="lineno"><a class="line" href="classhelib_1_1_context.html#a1eae4b3032d34226da9b04897b414179">  208</a></span>&#160;  <span class="keywordtype">double</span> <a class="code" href="classhelib_1_1_context.html#a1eae4b3032d34226da9b04897b414179">noiseBoundForSmall</a>(<span class="keywordtype">double</span> prob, <span class="keywordtype">long</span> degBound)<span class="keyword"> const</span></div>
<div class="line"><a name="l00209"></a><span class="lineno">  209</span>&#160;<span class="keyword">  </span>{</div>
<div class="line"><a name="l00210"></a><span class="lineno">  210</span>&#160;    <span class="keywordflow">return</span> <a class="code" href="classhelib_1_1_context.html#a86b3d6e90031da9bc9cef6f46e9e9bda">scale</a> * std::sqrt(<span class="keywordtype">double</span>(degBound)) * std::sqrt(prob);</div>
<div class="line"><a name="l00211"></a><span class="lineno">  211</span>&#160;  }</div>
<div class="line"><a name="l00212"></a><span class="lineno">  212</span>&#160; </div>
<div class="line"><a name="l00213"></a><span class="lineno">  213</span>&#160;  <span class="comment">//=======================================</span></div>
<div class="line"><a name="l00214"></a><span class="lineno">  214</span>&#160; </div>
<div class="line"><a name="l00220"></a><span class="lineno">  220</span>&#160; </div>
<div class="line"><a name="l00221"></a><span class="lineno">  221</span>&#160;  <span class="comment">// NOTE: this is a bit heuristic: we assume that if we evaluate</span></div>
<div class="line"><a name="l00222"></a><span class="lineno">  222</span>&#160;  <span class="comment">// f at a primitive root of unity, then we get something that</span></div>
<div class="line"><a name="l00223"></a><span class="lineno">  223</span>&#160;  <span class="comment">// well approximates a normal random variable with the same variance,</span></div>
<div class="line"><a name="l00224"></a><span class="lineno">  224</span>&#160;  <span class="comment">// which is hwt.</span></div>
<div class="line"><a name="l00225"></a><span class="lineno">  225</span>&#160;  <span class="comment">// We then multiply the sqrt of the variance by scale to get</span></div>
<div class="line"><a name="l00226"></a><span class="lineno">  226</span>&#160;  <span class="comment">// the high probability bound.</span></div>
<div class="line"><a name="l00227"></a><span class="lineno">  227</span>&#160; </div>
<div class="line"><a name="l00228"></a><span class="lineno">  228</span>&#160;  <span class="comment">// NOTE: degBound is not used here, but I include it</span></div>
<div class="line"><a name="l00229"></a><span class="lineno">  229</span>&#160;  <span class="comment">// for consistency with the other noiseBound routines</span></div>
<div class="line"><a name="l00230"></a><span class="lineno">  230</span>&#160; </div>
<div class="line"><a name="l00231"></a><span class="lineno"><a class="line" href="classhelib_1_1_context.html#aca4f48776f48a323315928889c64f0d1">  231</a></span>&#160;  <span class="keywordtype">double</span> <a class="code" href="classhelib_1_1_context.html#aca4f48776f48a323315928889c64f0d1">noiseBoundForHWt</a>(<span class="keywordtype">long</span> hwt, <a class="code" href="api_attributes_8h.html#addf5ec070e9499d36b7f2009ce736076">UNUSED</a> <span class="keywordtype">long</span> degBound)<span class="keyword"> const</span></div>
<div class="line"><a name="l00232"></a><span class="lineno">  232</span>&#160;<span class="keyword">  </span>{</div>
<div class="line"><a name="l00233"></a><span class="lineno">  233</span>&#160;    <span class="keywordflow">return</span> <a class="code" href="classhelib_1_1_context.html#a86b3d6e90031da9bc9cef6f46e9e9bda">scale</a> * std::sqrt(<span class="keywordtype">double</span>(hwt));</div>
<div class="line"><a name="l00234"></a><span class="lineno">  234</span>&#160;  }</div>
<div class="line"><a name="l00235"></a><span class="lineno">  235</span>&#160; </div>
<div class="line"><a name="l00236"></a><span class="lineno">  236</span>&#160;  <span class="comment">//=======================================</span></div>
<div class="line"><a name="l00237"></a><span class="lineno">  237</span>&#160; </div>
<div class="line"><a name="l00245"></a><span class="lineno">  245</span>&#160; </div>
<div class="line"><a name="l00247"></a><span class="lineno">  247</span>&#160; </div>
<div class="line"><a name="l00249"></a><span class="lineno">  249</span>&#160; </div>
<div class="line"><a name="l00250"></a><span class="lineno"><a class="line" href="classhelib_1_1_context.html#a30037bfeed9ef5a4282e10b92c149801">  250</a></span>&#160;  <span class="keywordtype">double</span> <a class="code" href="classhelib_1_1_context.html#a30037bfeed9ef5a4282e10b92c149801">stdDevForRecryption</a>(<span class="keywordtype">long</span> skHwt = 0)<span class="keyword"> const</span></div>
<div class="line"><a name="l00251"></a><span class="lineno">  251</span>&#160;<span class="keyword">  </span>{</div>
<div class="line"><a name="l00252"></a><span class="lineno">  252</span>&#160;    <span class="keywordflow">if</span> (!skHwt)</div>
<div class="line"><a name="l00253"></a><span class="lineno">  253</span>&#160;      skHwt = <a class="code" href="classhelib_1_1_context.html#af6b7e88d642f51a00c08263aebaa2e20">rcData</a>.<a class="code" href="classhelib_1_1_recrypt_data.html#a6e9384f58128b7a75b9a1f66842fbb5b">skHwt</a>;</div>
<div class="line"><a name="l00254"></a><span class="lineno">  254</span>&#160;    <span class="comment">// the default reverts to rcData.skHwt, *not* rcData.defSkHwt</span></div>
<div class="line"><a name="l00255"></a><span class="lineno">  255</span>&#160; </div>
<div class="line"><a name="l00256"></a><span class="lineno">  256</span>&#160;    <span class="keywordtype">long</span> k = <a class="code" href="classhelib_1_1_context.html#ab261446cf0a635a7bf1edf081df48d81">zMStar</a>.<a class="code" href="classhelib_1_1_p_algebra.html#afb8bd85921189335d6d6f2fe30011907">getNFactors</a>();</div>
<div class="line"><a name="l00257"></a><span class="lineno">  257</span>&#160;    <span class="comment">// number of prime factors of m</span></div>
<div class="line"><a name="l00258"></a><span class="lineno">  258</span>&#160; </div>
<div class="line"><a name="l00259"></a><span class="lineno">  259</span>&#160;    <span class="keywordtype">long</span> m = <a class="code" href="classhelib_1_1_context.html#ab261446cf0a635a7bf1edf081df48d81">zMStar</a>.<a class="code" href="classhelib_1_1_p_algebra.html#a6852047dd695a0b1ae1a5ea03c3b2c53">getM</a>();</div>
<div class="line"><a name="l00260"></a><span class="lineno">  260</span>&#160;    <span class="keywordtype">long</span> phim = <a class="code" href="classhelib_1_1_context.html#ab261446cf0a635a7bf1edf081df48d81">zMStar</a>.<a class="code" href="classhelib_1_1_p_algebra.html#a4422e1911052282a6881fa97ae5061dd">getPhiM</a>();</div>
<div class="line"><a name="l00261"></a><span class="lineno">  261</span>&#160; </div>
<div class="line"><a name="l00262"></a><span class="lineno">  262</span>&#160;    <span class="keywordtype">double</span> mrat = double(phim) / double(m);</div>
<div class="line"><a name="l00263"></a><span class="lineno">  263</span>&#160; </div>
<div class="line"><a name="l00264"></a><span class="lineno">  264</span>&#160;    <span class="keywordflow">return</span> std::sqrt(mrat * <span class="keywordtype">double</span>(skHwt) * <span class="keywordtype">double</span>(1L &lt;&lt; k) / 3.0) * 0.5;</div>
<div class="line"><a name="l00265"></a><span class="lineno">  265</span>&#160;  }</div>
<div class="line"><a name="l00266"></a><span class="lineno">  266</span>&#160; </div>
<div class="line"><a name="l00267"></a><span class="lineno"><a class="line" href="classhelib_1_1_context.html#a6d1a18803b7a39ff477bf3318aa98be5">  267</a></span>&#160;  <span class="keywordtype">double</span> <a class="code" href="classhelib_1_1_context.html#a6d1a18803b7a39ff477bf3318aa98be5">boundForRecryption</a>(<span class="keywordtype">long</span> skHwt = 0)<span class="keyword"> const</span></div>
<div class="line"><a name="l00268"></a><span class="lineno">  268</span>&#160;<span class="keyword">  </span>{</div>
<div class="line"><a name="l00269"></a><span class="lineno">  269</span>&#160;    <span class="keywordtype">double</span> c_m = <a class="code" href="classhelib_1_1_context.html#ab261446cf0a635a7bf1edf081df48d81">zMStar</a>.<a class="code" href="classhelib_1_1_p_algebra.html#a3dcfa1c03e7f17674c16e9d25687f87a">get_cM</a>();</div>
<div class="line"><a name="l00270"></a><span class="lineno">  270</span>&#160;    <span class="comment">// multiply by this fudge factor</span></div>
<div class="line"><a name="l00271"></a><span class="lineno">  271</span>&#160; </div>
<div class="line"><a name="l00272"></a><span class="lineno">  272</span>&#160;    <span class="keywordflow">return</span> 0.5 + c_m * <a class="code" href="classhelib_1_1_context.html#a86b3d6e90031da9bc9cef6f46e9e9bda">scale</a> * <a class="code" href="classhelib_1_1_context.html#a30037bfeed9ef5a4282e10b92c149801">stdDevForRecryption</a>(skHwt);</div>
<div class="line"><a name="l00273"></a><span class="lineno">  273</span>&#160;  }</div>
<div class="line"><a name="l00274"></a><span class="lineno">  274</span>&#160; </div>
<div class="line"><a name="l00280"></a><span class="lineno"><a class="line" href="classhelib_1_1_context.html#a09e894a14a98620a7f129c992468072f">  280</a></span>&#160;  <a class="code" href="classhelib_1_1_index_set.html">IndexSet</a> <a class="code" href="classhelib_1_1_context.html#a09e894a14a98620a7f129c992468072f">ctxtPrimes</a>;</div>
<div class="line"><a name="l00281"></a><span class="lineno">  281</span>&#160; </div>
<div class="line"><a name="l00285"></a><span class="lineno"><a class="line" href="classhelib_1_1_context.html#a4237638ccaec9233a0c7edaf334343b2">  285</a></span>&#160;  <a class="code" href="classhelib_1_1_index_set.html">IndexSet</a> <a class="code" href="classhelib_1_1_context.html#a4237638ccaec9233a0c7edaf334343b2">specialPrimes</a>;</div>
<div class="line"><a name="l00286"></a><span class="lineno">  286</span>&#160; </div>
<div class="line"><a name="l00290"></a><span class="lineno"><a class="line" href="classhelib_1_1_context.html#a9d52169353df3e667210c59c1643e316">  290</a></span>&#160;  <a class="code" href="classhelib_1_1_index_set.html">IndexSet</a> <a class="code" href="classhelib_1_1_context.html#a9d52169353df3e667210c59c1643e316">smallPrimes</a>;</div>
<div class="line"><a name="l00291"></a><span class="lineno">  291</span>&#160; </div>
<div class="line"><a name="l00293"></a><span class="lineno"><a class="line" href="classhelib_1_1_context.html#a739f1b2cb1d0738bcdd8e5474fb05922">  293</a></span>&#160;  <a class="code" href="classhelib_1_1_moduli_sizes.html">ModuliSizes</a> <a class="code" href="classhelib_1_1_context.html#a739f1b2cb1d0738bcdd8e5474fb05922">modSizes</a>;</div>
<div class="line"><a name="l00294"></a><span class="lineno"><a class="line" href="classhelib_1_1_context.html#a400f1f138bef615ed0b8f19bdc2bd8ce">  294</a></span>&#160;  <span class="keywordtype">void</span> <a class="code" href="classhelib_1_1_context.html#a400f1f138bef615ed0b8f19bdc2bd8ce">setModSizeTable</a>() { <a class="code" href="classhelib_1_1_context.html#a739f1b2cb1d0738bcdd8e5474fb05922">modSizes</a>.<a class="code" href="classhelib_1_1_moduli_sizes.html#ad621f5c0fa4ce4bf037888eadb7db437">init</a>(moduli, <a class="code" href="classhelib_1_1_context.html#a09e894a14a98620a7f129c992468072f">ctxtPrimes</a>, <a class="code" href="classhelib_1_1_context.html#a9d52169353df3e667210c59c1643e316">smallPrimes</a>); }</div>
<div class="line"><a name="l00295"></a><span class="lineno">  295</span>&#160; </div>
<div class="line"><a name="l00312"></a><span class="lineno">  312</span>&#160;  <span class="comment">// Digits of ctxt/columns of key-switching matrix</span></div>
<div class="line"><a name="l00313"></a><span class="lineno"><a class="line" href="classhelib_1_1_context.html#a221facd004b3ace6f11367d6766f9b78">  313</a></span>&#160;  std::vector&lt;IndexSet&gt; <a class="code" href="classhelib_1_1_context.html#a221facd004b3ace6f11367d6766f9b78">digits</a>;</div>
<div class="line"><a name="l00314"></a><span class="lineno">  314</span>&#160; </div>
<div class="line"><a name="l00316"></a><span class="lineno">  316</span>&#160;  <span class="comment">// includes both thin and thick</span></div>
<div class="line"><a name="l00317"></a><span class="lineno"><a class="line" href="classhelib_1_1_context.html#af6b7e88d642f51a00c08263aebaa2e20">  317</a></span>&#160;  <a class="code" href="classhelib_1_1_thin_recrypt_data.html">ThinRecryptData</a> <a class="code" href="classhelib_1_1_context.html#af6b7e88d642f51a00c08263aebaa2e20">rcData</a>;</div>
<div class="line"><a name="l00318"></a><span class="lineno">  318</span>&#160; </div>
<div class="line"><a name="l00319"></a><span class="lineno">  319</span>&#160;<span class="comment">  /******************************************************************/</span></div>
<div class="line"><a name="l00320"></a><span class="lineno">  320</span>&#160;  <span class="comment">// constructor</span></div>
<div class="line"><a name="l00321"></a><span class="lineno">  321</span>&#160;  <a class="code" href="classhelib_1_1_context.html#a08ad8299f225b9f8603f8936a98c2453">Context</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> m,</div>
<div class="line"><a name="l00322"></a><span class="lineno">  322</span>&#160;          <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> p,</div>
<div class="line"><a name="l00323"></a><span class="lineno">  323</span>&#160;          <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> r,</div>
<div class="line"><a name="l00324"></a><span class="lineno">  324</span>&#160;          <span class="keyword">const</span> std::vector&lt;long&gt;&amp; gens = std::vector&lt;long&gt;(),</div>
<div class="line"><a name="l00325"></a><span class="lineno">  325</span>&#160;          <span class="keyword">const</span> std::vector&lt;long&gt;&amp; ords = std::vector&lt;long&gt;());</div>
<div class="line"><a name="l00326"></a><span class="lineno">  326</span>&#160; </div>
<div class="line"><a name="l00327"></a><span class="lineno"><a class="line" href="classhelib_1_1_context.html#aeb97afc7e74b0b7522c4168d8db2b374">  327</a></span>&#160;  <span class="keywordtype">void</span> <a class="code" href="classhelib_1_1_context.html#aeb97afc7e74b0b7522c4168d8db2b374">makeBootstrappable</a>(<span class="keyword">const</span> NTL::Vec&lt;long&gt;&amp; mvec,</div>
<div class="line"><a name="l00328"></a><span class="lineno">  328</span>&#160;                          <span class="keywordtype">long</span> skWht = 0,</div>
<div class="line"><a name="l00329"></a><span class="lineno">  329</span>&#160;                          <span class="keywordtype">bool</span> build_cache = <span class="keyword">false</span>,</div>
<div class="line"><a name="l00330"></a><span class="lineno">  330</span>&#160;                          <span class="keywordtype">bool</span> alsoThick = <span class="keyword">true</span>)</div>
<div class="line"><a name="l00331"></a><span class="lineno">  331</span>&#160;  {</div>
<div class="line"><a name="l00332"></a><span class="lineno">  332</span>&#160;    <a class="code" href="classhelib_1_1_context.html#af6b7e88d642f51a00c08263aebaa2e20">rcData</a>.<a class="code" href="classhelib_1_1_thin_recrypt_data.html#accba45a87da96c0545b19c82d20c2da0">init</a>(*<span class="keyword">this</span>, mvec, alsoThick, skWht, build_cache);</div>
<div class="line"><a name="l00333"></a><span class="lineno">  333</span>&#160;  }</div>
<div class="line"><a name="l00334"></a><span class="lineno">  334</span>&#160; </div>
<div class="line"><a name="l00335"></a><span class="lineno"><a class="line" href="classhelib_1_1_context.html#abb8f32691d102e0390b5770526c8d4fd">  335</a></span>&#160;  <span class="keywordtype">bool</span> <a class="code" href="classhelib_1_1_context.html#abb8f32691d102e0390b5770526c8d4fd">isBootstrappable</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> <a class="code" href="classhelib_1_1_context.html#af6b7e88d642f51a00c08263aebaa2e20">rcData</a>.<a class="code" href="classhelib_1_1_recrypt_data.html#aa33d0f2a11a834d4c4eda0cd4513b3c0">alMod</a> != <span class="keyword">nullptr</span>; }</div>
<div class="line"><a name="l00336"></a><span class="lineno">  336</span>&#160; </div>
<div class="line"><a name="l00337"></a><span class="lineno"><a class="line" href="classhelib_1_1_context.html#a8f143c4d8e8fde51e2fce121a904eb0a">  337</a></span>&#160;  <a class="code" href="classhelib_1_1_index_set.html">IndexSet</a> <a class="code" href="classhelib_1_1_context.html#a8f143c4d8e8fde51e2fce121a904eb0a">fullPrimes</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> <a class="code" href="classhelib_1_1_context.html#a09e894a14a98620a7f129c992468072f">ctxtPrimes</a> | <a class="code" href="classhelib_1_1_context.html#a4237638ccaec9233a0c7edaf334343b2">specialPrimes</a>; }</div>
<div class="line"><a name="l00338"></a><span class="lineno">  338</span>&#160; </div>
<div class="line"><a name="l00339"></a><span class="lineno"><a class="line" href="classhelib_1_1_context.html#acb3ebd14d55203e09b351b88eca17a44">  339</a></span>&#160;  <a class="code" href="classhelib_1_1_index_set.html">IndexSet</a> <a class="code" href="classhelib_1_1_context.html#acb3ebd14d55203e09b351b88eca17a44">allPrimes</a>()<span class="keyword"> const</span></div>
<div class="line"><a name="l00340"></a><span class="lineno">  340</span>&#160;<span class="keyword">  </span>{</div>
<div class="line"><a name="l00341"></a><span class="lineno">  341</span>&#160;    <span class="keywordflow">return</span> <a class="code" href="classhelib_1_1_context.html#a9d52169353df3e667210c59c1643e316">smallPrimes</a> | <a class="code" href="classhelib_1_1_context.html#a09e894a14a98620a7f129c992468072f">ctxtPrimes</a> | <a class="code" href="classhelib_1_1_context.html#a4237638ccaec9233a0c7edaf334343b2">specialPrimes</a>;</div>
<div class="line"><a name="l00342"></a><span class="lineno">  342</span>&#160;  }</div>
<div class="line"><a name="l00343"></a><span class="lineno">  343</span>&#160; </div>
<div class="line"><a name="l00344"></a><span class="lineno">  344</span>&#160;  <span class="comment">// returns first nprimes ctxtPrimes</span></div>
<div class="line"><a name="l00345"></a><span class="lineno"><a class="line" href="classhelib_1_1_context.html#abfe778f83df73ee943f9fc25741efa2e">  345</a></span>&#160;  <a class="code" href="classhelib_1_1_index_set.html">IndexSet</a> <a class="code" href="classhelib_1_1_context.html#abfe778f83df73ee943f9fc25741efa2e">getCtxtPrimes</a>(<span class="keywordtype">long</span> nprimes)<span class="keyword"> const</span></div>
<div class="line"><a name="l00346"></a><span class="lineno">  346</span>&#160;<span class="keyword">  </span>{</div>
<div class="line"><a name="l00347"></a><span class="lineno">  347</span>&#160;    <span class="keywordtype">long</span> first = <a class="code" href="classhelib_1_1_context.html#a09e894a14a98620a7f129c992468072f">ctxtPrimes</a>.<a class="code" href="classhelib_1_1_index_set.html#a30a96e32a1bec249fb56f83bbb6f4afa">first</a>();</div>
<div class="line"><a name="l00348"></a><span class="lineno">  348</span>&#160;    <span class="keywordtype">long</span> last = std::min(<a class="code" href="classhelib_1_1_context.html#a09e894a14a98620a7f129c992468072f">ctxtPrimes</a>.<a class="code" href="classhelib_1_1_index_set.html#a8156f49ca3715bf0cf9c63ac8dc02172">last</a>(), first + nprimes - 1);</div>
<div class="line"><a name="l00349"></a><span class="lineno">  349</span>&#160;    <span class="keywordflow">return</span> <a class="code" href="classhelib_1_1_index_set.html">IndexSet</a>(first, last);</div>
<div class="line"><a name="l00350"></a><span class="lineno">  350</span>&#160;  }</div>
<div class="line"><a name="l00351"></a><span class="lineno">  351</span>&#160; </div>
<div class="line"><a name="l00352"></a><span class="lineno">  352</span>&#160;  <span class="comment">// FIXME: replacement for bitsPerLevel...placeholder for now</span></div>
<div class="line"><a name="l00353"></a><span class="lineno"><a class="line" href="classhelib_1_1_context.html#a3feef5466cf8ed4878446d0142ac0be4">  353</a></span>&#160;  <span class="keywordtype">long</span> <a class="code" href="classhelib_1_1_context.html#a3feef5466cf8ed4878446d0142ac0be4">BPL</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> 30; }</div>
<div class="line"><a name="l00354"></a><span class="lineno">  354</span>&#160; </div>
<div class="line"><a name="l00355"></a><span class="lineno">  355</span>&#160;  <span class="keywordtype">bool</span> <a class="code" href="classhelib_1_1_context.html#ae6f113ef16d2e6c1ca451411e34eed42">operator==</a>(<span class="keyword">const</span> <a class="code" href="classhelib_1_1_context.html">Context</a>&amp; other) <span class="keyword">const</span>;</div>
<div class="line"><a name="l00356"></a><span class="lineno"><a class="line" href="classhelib_1_1_context.html#a3d08d9248d0d3165fa5914b95bd60fdf">  356</a></span>&#160;  <span class="keywordtype">bool</span> <a class="code" href="classhelib_1_1_context.html#a3d08d9248d0d3165fa5914b95bd60fdf">operator!=</a>(<span class="keyword">const</span> <a class="code" href="classhelib_1_1_context.html">Context</a>&amp; other)<span class="keyword"> const </span>{ <span class="keywordflow">return</span> !(*<span class="keyword">this</span> == other); }</div>
<div class="line"><a name="l00357"></a><span class="lineno">  357</span>&#160; </div>
<div class="line"><a name="l00359"></a><span class="lineno"><a class="line" href="classhelib_1_1_context.html#aa2da1bad87f9c90f15b70cb14777685d">  359</a></span>&#160;  <span class="keywordtype">long</span> <a class="code" href="classhelib_1_1_context.html#aa2da1bad87f9c90f15b70cb14777685d">ithPrime</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> i)<span class="keyword"> const</span></div>
<div class="line"><a name="l00360"></a><span class="lineno">  360</span>&#160;<span class="keyword">  </span>{</div>
<div class="line"><a name="l00361"></a><span class="lineno">  361</span>&#160;    <span class="keywordflow">return</span> (i &lt; moduli.size()) ? moduli[i].getQ() : 0;</div>
<div class="line"><a name="l00362"></a><span class="lineno">  362</span>&#160;  }</div>
<div class="line"><a name="l00363"></a><span class="lineno">  363</span>&#160; </div>
<div class="line"><a name="l00365"></a><span class="lineno"><a class="line" href="classhelib_1_1_context.html#ad066ba083a3ba9f4b9627fde8bfa17fe">  365</a></span>&#160;  <span class="keyword">const</span> <a class="code" href="classhelib_1_1_cmodulus.html">Cmodulus</a>&amp; <a class="code" href="classhelib_1_1_context.html#ad066ba083a3ba9f4b9627fde8bfa17fe">ithModulus</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> i)<span class="keyword"> const </span>{ <span class="keywordflow">return</span> moduli[i]; }</div>
<div class="line"><a name="l00366"></a><span class="lineno">  366</span>&#160; </div>
<div class="line"><a name="l00368"></a><span class="lineno"><a class="line" href="classhelib_1_1_context.html#a552e300656dfae6eaacace769c03655a">  368</a></span>&#160;  <span class="keywordtype">long</span> <a class="code" href="classhelib_1_1_context.html#a552e300656dfae6eaacace769c03655a">numPrimes</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> moduli.size(); }</div>
<div class="line"><a name="l00369"></a><span class="lineno">  369</span>&#160; </div>
<div class="line"><a name="l00371"></a><span class="lineno"><a class="line" href="classhelib_1_1_context.html#a2b87d5f0041ad5abe2bcf358cb818343">  371</a></span>&#160;  <span class="keywordtype">bool</span> <a class="code" href="classhelib_1_1_context.html#a2b87d5f0041ad5abe2bcf358cb818343">isZeroDivisor</a>(<span class="keyword">const</span> NTL::ZZ&amp; num)<span class="keyword"> const</span></div>
<div class="line"><a name="l00372"></a><span class="lineno">  372</span>&#160;<span class="keyword">  </span>{</div>
<div class="line"><a name="l00373"></a><span class="lineno">  373</span>&#160;    <span class="keywordflow">for</span> (<span class="keywordtype">long</span> i : <a class="code" href="namespacehelib.html#a5dcff6470686ad80a2319fa1652ac1e3">range</a>(moduli.size()))</div>
<div class="line"><a name="l00374"></a><span class="lineno">  374</span>&#160;      <span class="keywordflow">if</span> (divide(num, moduli[i].getQ()))</div>
<div class="line"><a name="l00375"></a><span class="lineno">  375</span>&#160;        <span class="keywordflow">return</span> <span class="keyword">true</span>;</div>
<div class="line"><a name="l00376"></a><span class="lineno">  376</span>&#160;    <span class="keywordflow">return</span> <span class="keyword">false</span>;</div>
<div class="line"><a name="l00377"></a><span class="lineno">  377</span>&#160;  }</div>
<div class="line"><a name="l00378"></a><span class="lineno">  378</span>&#160; </div>
<div class="line"><a name="l00380"></a><span class="lineno"><a class="line" href="classhelib_1_1_context.html#a9dea4625a64c673ad3147bf18a1d231f">  380</a></span>&#160;  <span class="keywordtype">bool</span> <a class="code" href="classhelib_1_1_context.html#a9dea4625a64c673ad3147bf18a1d231f">inChain</a>(<span class="keywordtype">long</span> p)<span class="keyword"> const</span></div>
<div class="line"><a name="l00381"></a><span class="lineno">  381</span>&#160;<span class="keyword">  </span>{</div>
<div class="line"><a name="l00382"></a><span class="lineno">  382</span>&#160;    <span class="keywordflow">for</span> (<span class="keywordtype">long</span> i : <a class="code" href="namespacehelib.html#a5dcff6470686ad80a2319fa1652ac1e3">range</a>(moduli.size()))</div>
<div class="line"><a name="l00383"></a><span class="lineno">  383</span>&#160;      <span class="keywordflow">if</span> (p == moduli[i].getQ())</div>
<div class="line"><a name="l00384"></a><span class="lineno">  384</span>&#160;        <span class="keywordflow">return</span> <span class="keyword">true</span>;</div>
<div class="line"><a name="l00385"></a><span class="lineno">  385</span>&#160;    <span class="keywordflow">return</span> <span class="keyword">false</span>;</div>
<div class="line"><a name="l00386"></a><span class="lineno">  386</span>&#160;  }</div>
<div class="line"><a name="l00387"></a><span class="lineno">  387</span>&#160; </div>
<div class="line"><a name="l00390"></a><span class="lineno">  390</span>&#160;  <span class="keywordtype">void</span> <a class="code" href="classhelib_1_1_context.html#afc6a3c91d2488abe71e82849653b2c40">productOfPrimes</a>(NTL::ZZ&amp; p, <span class="keyword">const</span> <a class="code" href="classhelib_1_1_index_set.html">IndexSet</a>&amp; s) <span class="keyword">const</span>;</div>
<div class="line"><a name="l00391"></a><span class="lineno"><a class="line" href="classhelib_1_1_context.html#aa10cb4160e67f8fc94dbbcd14be3a7c5">  391</a></span>&#160;  NTL::ZZ <a class="code" href="classhelib_1_1_context.html#aa10cb4160e67f8fc94dbbcd14be3a7c5">productOfPrimes</a>(<span class="keyword">const</span> <a class="code" href="classhelib_1_1_index_set.html">IndexSet</a>&amp; s)<span class="keyword"> const</span></div>
<div class="line"><a name="l00392"></a><span class="lineno">  392</span>&#160;<span class="keyword">  </span>{</div>
<div class="line"><a name="l00393"></a><span class="lineno">  393</span>&#160;    NTL::ZZ p;</div>
<div class="line"><a name="l00394"></a><span class="lineno">  394</span>&#160;    <a class="code" href="classhelib_1_1_context.html#afc6a3c91d2488abe71e82849653b2c40">productOfPrimes</a>(p, s);</div>
<div class="line"><a name="l00395"></a><span class="lineno">  395</span>&#160;    <span class="keywordflow">return</span> p;</div>
<div class="line"><a name="l00396"></a><span class="lineno">  396</span>&#160;  }</div>
<div class="line"><a name="l00398"></a><span class="lineno">  398</span>&#160; </div>
<div class="line"><a name="l00399"></a><span class="lineno">  399</span>&#160;  <span class="comment">// FIXME: run-time error when ithPrime(i) returns 0</span></div>
<div class="line"><a name="l00401"></a><span class="lineno"><a class="line" href="classhelib_1_1_context.html#abd63a1dac045b9e1225e9b42b7506e64">  401</a></span>&#160;<span class="comment"></span>  <span class="keywordtype">double</span> <a class="code" href="classhelib_1_1_context.html#abd63a1dac045b9e1225e9b42b7506e64">logOfPrime</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> i)<span class="keyword"> const </span>{ <span class="keywordflow">return</span> log(<a class="code" href="classhelib_1_1_context.html#aa2da1bad87f9c90f15b70cb14777685d">ithPrime</a>(i)); }</div>
<div class="line"><a name="l00402"></a><span class="lineno">  402</span>&#160; </div>
<div class="line"><a name="l00404"></a><span class="lineno"><a class="line" href="classhelib_1_1_context.html#a237f432913ec39edc41af03384d4475d">  404</a></span>&#160;  <span class="keywordtype">double</span> <a class="code" href="classhelib_1_1_context.html#a237f432913ec39edc41af03384d4475d">logOfProduct</a>(<span class="keyword">const</span> <a class="code" href="classhelib_1_1_index_set.html">IndexSet</a>&amp; s)<span class="keyword"> const</span></div>
<div class="line"><a name="l00405"></a><span class="lineno">  405</span>&#160;<span class="keyword">  </span>{</div>
<div class="line"><a name="l00406"></a><span class="lineno">  406</span>&#160;    <span class="keywordflow">if</span> (s.<a class="code" href="classhelib_1_1_index_set.html#a8156f49ca3715bf0cf9c63ac8dc02172">last</a>() &gt;= <a class="code" href="classhelib_1_1_context.html#a552e300656dfae6eaacace769c03655a">numPrimes</a>())</div>
<div class="line"><a name="l00407"></a><span class="lineno">  407</span>&#160;      <span class="keywordflow">throw</span> <a class="code" href="classhelib_1_1_runtime_error.html">RuntimeError</a>(<span class="stringliteral">&quot;Context::logOfProduct: IndexSet has too many rows&quot;</span>);</div>
<div class="line"><a name="l00408"></a><span class="lineno">  408</span>&#160; </div>
<div class="line"><a name="l00409"></a><span class="lineno">  409</span>&#160;    <span class="keywordtype">double</span> ans = 0.0;</div>
<div class="line"><a name="l00410"></a><span class="lineno">  410</span>&#160;    <span class="keywordflow">for</span> (<span class="keywordtype">long</span> i : s)</div>
<div class="line"><a name="l00411"></a><span class="lineno">  411</span>&#160;      ans += <a class="code" href="classhelib_1_1_context.html#abd63a1dac045b9e1225e9b42b7506e64">logOfPrime</a>(i);</div>
<div class="line"><a name="l00412"></a><span class="lineno">  412</span>&#160;    <span class="keywordflow">return</span> ans;</div>
<div class="line"><a name="l00413"></a><span class="lineno">  413</span>&#160;  }</div>
<div class="line"><a name="l00414"></a><span class="lineno">  414</span>&#160; </div>
<div class="line"><a name="l00416"></a><span class="lineno"><a class="line" href="classhelib_1_1_context.html#a065f668db1a4712692fdd2ea9c70dc47">  416</a></span>&#160;  <span class="keywordtype">double</span> <a class="code" href="classhelib_1_1_context.html#a065f668db1a4712692fdd2ea9c70dc47">securityLevel</a>()<span class="keyword"> const</span></div>
<div class="line"><a name="l00417"></a><span class="lineno">  417</span>&#160;<span class="keyword">  </span>{</div>
<div class="line"><a name="l00418"></a><span class="lineno">  418</span>&#160;    <span class="keywordtype">long</span> phim = <a class="code" href="classhelib_1_1_context.html#ab261446cf0a635a7bf1edf081df48d81">zMStar</a>.<a class="code" href="classhelib_1_1_p_algebra.html#a4422e1911052282a6881fa97ae5061dd">getPhiM</a>();</div>
<div class="line"><a name="l00419"></a><span class="lineno">  419</span>&#160;    <a class="code" href="classhelib_1_1_index_set.html">IndexSet</a> primes = <a class="code" href="classhelib_1_1_context.html#a09e894a14a98620a7f129c992468072f">ctxtPrimes</a> | <a class="code" href="classhelib_1_1_context.html#a4237638ccaec9233a0c7edaf334343b2">specialPrimes</a>;</div>
<div class="line"><a name="l00420"></a><span class="lineno">  420</span>&#160; </div>
<div class="line"><a name="l00421"></a><span class="lineno">  421</span>&#160;    <span class="keywordflow">if</span> (primes.<a class="code" href="classhelib_1_1_index_set.html#a018572f1e76bc3c9750491f2cf02c7ca">card</a>() == 0) {</div>
<div class="line"><a name="l00422"></a><span class="lineno">  422</span>&#160;      <span class="keywordflow">throw</span> <a class="code" href="classhelib_1_1_logic_error.html">LogicError</a>(</div>
<div class="line"><a name="l00423"></a><span class="lineno">  423</span>&#160;          <span class="stringliteral">&quot;Security level cannot be determined as modulus chain is empty.&quot;</span>);</div>
<div class="line"><a name="l00424"></a><span class="lineno">  424</span>&#160;    }</div>
<div class="line"><a name="l00425"></a><span class="lineno">  425</span>&#160; </div>
<div class="line"><a name="l00426"></a><span class="lineno">  426</span>&#160;    <span class="keywordtype">double</span> bitsize = <a class="code" href="classhelib_1_1_context.html#a237f432913ec39edc41af03384d4475d">logOfProduct</a>(primes) / log(2.0);</div>
<div class="line"><a name="l00427"></a><span class="lineno">  427</span>&#160;    <span class="keywordflow">return</span> (7.2 * phim / bitsize - 110);</div>
<div class="line"><a name="l00428"></a><span class="lineno">  428</span>&#160;  }</div>
<div class="line"><a name="l00429"></a><span class="lineno">  429</span>&#160; </div>
<div class="line"><a name="l00431"></a><span class="lineno">  431</span>&#160;  <span class="keywordtype">void</span> <a class="code" href="classhelib_1_1_context.html#aa65a6f2210ee990f8f3d4cbc60a6060a">AddSmallPrime</a>(<span class="keywordtype">long</span> q);</div>
<div class="line"><a name="l00432"></a><span class="lineno">  432</span>&#160;  <span class="keywordtype">void</span> <a class="code" href="classhelib_1_1_context.html#af915dcf0e80c5014ef2dc6911891262d">AddCtxtPrime</a>(<span class="keywordtype">long</span> q);</div>
<div class="line"><a name="l00433"></a><span class="lineno">  433</span>&#160;  <span class="keywordtype">void</span> <a class="code" href="classhelib_1_1_context.html#acc2c4b8400734e630cebe544fbf01cc1">AddSpecialPrime</a>(<span class="keywordtype">long</span> q);</div>
<div class="line"><a name="l00434"></a><span class="lineno">  434</span>&#160; </div>
<div class="line"><a name="l00436"></a><span class="lineno">  436</span>&#160; </div>
<div class="line"><a name="l00471"></a><span class="lineno">  471</span>&#160;  <span class="keyword">friend</span> <span class="keywordtype">void</span> <a class="code" href="classhelib_1_1_context.html#a3a9a7a348aecd453c92d1c077a9af03d">writeContextBase</a>(std::ostream&amp; str, <span class="keyword">const</span> <a class="code" href="classhelib_1_1_context.html">Context</a>&amp; context);</div>
<div class="line"><a name="l00473"></a><span class="lineno">  473</span>&#160; </div>
<div class="line"><a name="l00475"></a><span class="lineno">  475</span>&#160;  <span class="keyword">friend</span> std::ostream&amp; <a class="code" href="classhelib_1_1_context.html#a3f25fcb8f7047c32e2929d9ffbf4ac11">operator&lt;&lt;</a>(std::ostream&amp; str, <span class="keyword">const</span> <a class="code" href="classhelib_1_1_context.html">Context</a>&amp; context);</div>
<div class="line"><a name="l00476"></a><span class="lineno">  476</span>&#160; </div>
<div class="line"><a name="l00478"></a><span class="lineno">  478</span>&#160;  <span class="keyword">friend</span> <span class="keywordtype">void</span> <a class="code" href="classhelib_1_1_context.html#a40d28a7b77f5735cc6d082452e7126a9">readContextBase</a>(std::istream&amp; str,</div>
<div class="line"><a name="l00479"></a><span class="lineno">  479</span>&#160;                              <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>&amp; m,</div>
<div class="line"><a name="l00480"></a><span class="lineno">  480</span>&#160;                              <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>&amp; p,</div>
<div class="line"><a name="l00481"></a><span class="lineno">  481</span>&#160;                              <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>&amp; r,</div>
<div class="line"><a name="l00482"></a><span class="lineno">  482</span>&#160;                              std::vector&lt;long&gt;&amp; gens,</div>
<div class="line"><a name="l00483"></a><span class="lineno">  483</span>&#160;                              std::vector&lt;long&gt;&amp; ords);</div>
<div class="line"><a name="l00484"></a><span class="lineno">  484</span>&#160; </div>
<div class="line"><a name="l00486"></a><span class="lineno">  486</span>&#160;  <span class="keyword">friend</span> std::istream&amp; <a class="code" href="classhelib_1_1_context.html#a717438f68d2a050214ee4a8a933a7bba">operator&gt;&gt;</a>(std::istream&amp; str, <a class="code" href="classhelib_1_1_context.html">Context</a>&amp; context);</div>
<div class="line"><a name="l00488"></a><span class="lineno">  488</span>&#160; </div>
<div class="line"><a name="l00489"></a><span class="lineno">  489</span>&#160;  <span class="keyword">friend</span> <span class="keywordtype">void</span> <a class="code" href="classhelib_1_1_context.html#a83165f2f0d0a6dd8bb3c3f227e7da1a3">writeContextBinary</a>(std::ostream&amp; str, <span class="keyword">const</span> <a class="code" href="classhelib_1_1_context.html">Context</a>&amp; context);</div>
<div class="line"><a name="l00490"></a><span class="lineno">  490</span>&#160;  <span class="keyword">friend</span> <span class="keywordtype">void</span> <a class="code" href="classhelib_1_1_context.html#ad1e445830c6007a7f725e100f19dfe6a">readContextBinary</a>(std::istream&amp; str, <a class="code" href="classhelib_1_1_context.html">Context</a>&amp; context);</div>
<div class="line"><a name="l00491"></a><span class="lineno">  491</span>&#160;};</div>
<div class="line"><a name="l00492"></a><span class="lineno">  492</span>&#160; </div>
<div class="line"><a name="l00494"></a><span class="lineno">  494</span>&#160;<span class="keywordtype">void</span> <a class="code" href="namespacehelib.html#a8425881cdaaef9fade4dd57cc3cf5e8b">writeContextBase</a>(std::ostream&amp; s, <span class="keyword">const</span> Context&amp; context);</div>
<div class="line"><a name="l00496"></a><span class="lineno">  496</span>&#160;<span class="keywordtype">void</span> <a class="code" href="namespacehelib.html#ab7b88eb3fd0aa4821cb6700fa65ecee2">readContextBase</a>(std::istream&amp; s,</div>
<div class="line"><a name="l00497"></a><span class="lineno">  497</span>&#160;                     <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>&amp; m,</div>
<div class="line"><a name="l00498"></a><span class="lineno">  498</span>&#160;                     <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>&amp; p,</div>
<div class="line"><a name="l00499"></a><span class="lineno">  499</span>&#160;                     <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>&amp; r,</div>
<div class="line"><a name="l00500"></a><span class="lineno">  500</span>&#160;                     std::vector&lt;long&gt;&amp; gens,</div>
<div class="line"><a name="l00501"></a><span class="lineno">  501</span>&#160;                     std::vector&lt;long&gt;&amp; ords);</div>
<div class="line"><a name="l00502"></a><span class="lineno">  502</span>&#160;std::unique_ptr&lt;Context&gt; <a class="code" href="namespacehelib.html#adcfd34a416649164e3b01c4af1c8654e">buildContextFromAscii</a>(std::istream&amp; str);</div>
<div class="line"><a name="l00503"></a><span class="lineno">  503</span>&#160; </div>
<div class="line"><a name="l00505"></a><span class="lineno">  505</span>&#160;<span class="keywordtype">void</span> <a class="code" href="namespacehelib.html#a3167b996c8b02f9f390d1d9957693b9f">writeContextBaseBinary</a>(std::ostream&amp; str, <span class="keyword">const</span> Context&amp; context);</div>
<div class="line"><a name="l00506"></a><span class="lineno">  506</span>&#160;<span class="keywordtype">void</span> <a class="code" href="namespacehelib.html#a1f9bc09cb4de5422bb79e9c4d67db80a">writeContextBinary</a>(std::ostream&amp; str, <span class="keyword">const</span> Context&amp; context);</div>
<div class="line"><a name="l00507"></a><span class="lineno">  507</span>&#160; </div>
<div class="line"><a name="l00509"></a><span class="lineno">  509</span>&#160;<span class="keywordtype">void</span> <a class="code" href="namespacehelib.html#acb88b203e4e9aeaf5fe329e7cc276aad">readContextBaseBinary</a>(std::istream&amp; s,</div>
<div class="line"><a name="l00510"></a><span class="lineno">  510</span>&#160;                           <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>&amp; m,</div>
<div class="line"><a name="l00511"></a><span class="lineno">  511</span>&#160;                           <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>&amp; p,</div>
<div class="line"><a name="l00512"></a><span class="lineno">  512</span>&#160;                           <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>&amp; r,</div>
<div class="line"><a name="l00513"></a><span class="lineno">  513</span>&#160;                           std::vector&lt;long&gt;&amp; gens,</div>
<div class="line"><a name="l00514"></a><span class="lineno">  514</span>&#160;                           std::vector&lt;long&gt;&amp; ords);</div>
<div class="line"><a name="l00515"></a><span class="lineno">  515</span>&#160;std::unique_ptr&lt;Context&gt; <a class="code" href="namespacehelib.html#a4036006b2d0e378ce2aa90a5332a8d73">buildContextFromBinary</a>(std::istream&amp; str);</div>
<div class="line"><a name="l00516"></a><span class="lineno">  516</span>&#160;<span class="keywordtype">void</span> <a class="code" href="namespacehelib.html#a4a07fadbe58c0bf5c4be26d9bb245755">readContextBinary</a>(std::istream&amp; str, Context&amp; context);</div>
<div class="line"><a name="l00517"></a><span class="lineno">  517</span>&#160; </div>
<div class="line"><a name="l00518"></a><span class="lineno">  518</span>&#160;<span class="comment">// Build modulus chain with nBits worth of ctxt primes,</span></div>
<div class="line"><a name="l00519"></a><span class="lineno">  519</span>&#160;<span class="comment">// using nDgts digits in key-switching.</span></div>
<div class="line"><a name="l00520"></a><span class="lineno">  520</span>&#160;<span class="comment">// The willBeBootstrappable and skHwt parameters are needed to get around some</span></div>
<div class="line"><a name="l00521"></a><span class="lineno">  521</span>&#160;<span class="comment">// some circularity when making the context boostrappable.</span></div>
<div class="line"><a name="l00522"></a><span class="lineno">  522</span>&#160;<span class="comment">// If you later call context.makeBootstrappable with a given value</span></div>
<div class="line"><a name="l00523"></a><span class="lineno">  523</span>&#160;<span class="comment">// of skHwt, you should first buildModChain with willBeBootstrappable</span></div>
<div class="line"><a name="l00524"></a><span class="lineno">  524</span>&#160;<span class="comment">// set to true and the given value of skHwt.</span></div>
<div class="line"><a name="l00525"></a><span class="lineno">  525</span>&#160;<span class="comment">// FIXME: We should really have a simpler way to do this.</span></div>
<div class="line"><a name="l00526"></a><span class="lineno">  526</span>&#160;<span class="comment">// resolution ... FIXME</span></div>
<div class="line"><a name="l00527"></a><span class="lineno">  527</span>&#160; </div>
<div class="line"><a name="l00528"></a><span class="lineno">  528</span>&#160;<span class="keywordtype">void</span> <a class="code" href="namespacehelib.html#af68cc874f7e017cd4c35d1ea52739c0f">buildModChain</a>(Context&amp; context,</div>
<div class="line"><a name="l00529"></a><span class="lineno">  529</span>&#160;                   <span class="keywordtype">long</span> nBits,</div>
<div class="line"><a name="l00530"></a><span class="lineno">  530</span>&#160;                   <span class="keywordtype">long</span> nDgts = 3,</div>
<div class="line"><a name="l00531"></a><span class="lineno">  531</span>&#160;                   <span class="keywordtype">bool</span> willBeBootstrappable = <span class="keyword">false</span>,</div>
<div class="line"><a name="l00532"></a><span class="lineno">  532</span>&#160;                   <span class="keywordtype">long</span> skHwt = 0,</div>
<div class="line"><a name="l00533"></a><span class="lineno">  533</span>&#160;                   <span class="keywordtype">long</span> resolution = 3,</div>
<div class="line"><a name="l00534"></a><span class="lineno">  534</span>&#160;                   <span class="keywordtype">long</span> bitsInSpecialPrimes = 0);</div>
<div class="line"><a name="l00535"></a><span class="lineno">  535</span>&#160;<span class="comment">// should be called if after you build the mod chain in some way</span></div>
<div class="line"><a name="l00536"></a><span class="lineno">  536</span>&#160;<span class="comment">// *other* than calling buildModChain.</span></div>
<div class="line"><a name="l00537"></a><span class="lineno">  537</span>&#160;<span class="keywordtype">void</span> <a class="code" href="namespacehelib.html#abcdd1f22927d282e9bbce15a18f5f3ad">endBuildModChain</a>(Context&amp; context);</div>
<div class="line"><a name="l00538"></a><span class="lineno">  538</span>&#160; </div>
<div class="line"><a name="l00540"></a><span class="lineno">  540</span>&#160;<span class="comment">// Should point to the &quot;current&quot; context</span></div>
<div class="line"><a name="l00541"></a><span class="lineno">  541</span>&#160;<span class="keyword">extern</span> Context* <a class="code" href="namespacehelib.html#a3ba322251033959f95b296f34745836e">activeContext</a>;</div>
<div class="line"><a name="l00542"></a><span class="lineno">  542</span>&#160; </div>
<div class="line"><a name="l00543"></a><span class="lineno">  543</span>&#160;} <span class="comment">// namespace helib</span></div>
<div class="line"><a name="l00544"></a><span class="lineno">  544</span>&#160; </div>
<div class="line"><a name="l00545"></a><span class="lineno">  545</span>&#160;<span class="preprocessor">#endif // ifndef HELIB_CONTEXT_H</span></div>
</div><!-- fragment --></div><!-- contents -->
<div class="ttc" id="aclasshelib_1_1_thin_recrypt_data_html"><div class="ttname"><a href="classhelib_1_1_thin_recrypt_data.html">helib::ThinRecryptData</a></div><div class="ttdoc">Same as above, but for &quot;thin&quot; bootstrapping, where the slots are assumed to contain constants.</div><div class="ttdef"><b>Definition:</b> recryption.h:123</div></div>
<div class="ttc" id="aclasshelib_1_1_context_html_a400f1f138bef615ed0b8f19bdc2bd8ce"><div class="ttname"><a href="classhelib_1_1_context.html#a400f1f138bef615ed0b8f19bdc2bd8ce">helib::Context::setModSizeTable</a></div><div class="ttdeci">void setModSizeTable()</div><div class="ttdef"><b>Definition:</b> Context.h:294</div></div>
<div class="ttc" id="aclasshelib_1_1_p_algebra_html_a6852047dd695a0b1ae1a5ea03c3b2c53"><div class="ttname"><a href="classhelib_1_1_p_algebra.html#a6852047dd695a0b1ae1a5ea03c3b2c53">helib::PAlgebra::getM</a></div><div class="ttdeci">long getM() const</div><div class="ttdoc">Returns m.</div><div class="ttdef"><b>Definition:</b> PAlgebra.h:162</div></div>
<div class="ttc" id="aclasshelib_1_1_runtime_error_html"><div class="ttname"><a href="classhelib_1_1_runtime_error.html">helib::RuntimeError</a></div><div class="ttdoc">Inherits from Exception and std::runtime_error.</div><div class="ttdef"><b>Definition:</b> exceptions.h:105</div></div>
<div class="ttc" id="aclasshelib_1_1_context_html_a739f1b2cb1d0738bcdd8e5474fb05922"><div class="ttname"><a href="classhelib_1_1_context.html#a739f1b2cb1d0738bcdd8e5474fb05922">helib::Context::modSizes</a></div><div class="ttdeci">ModuliSizes modSizes</div><div class="ttdoc">A helper table to map required modulo-sizes to primeSets.</div><div class="ttdef"><b>Definition:</b> Context.h:293</div></div>
<div class="ttc" id="anamespacehelib_html_abcdd1f22927d282e9bbce15a18f5f3ad"><div class="ttname"><a href="namespacehelib.html#abcdd1f22927d282e9bbce15a18f5f3ad">helib::endBuildModChain</a></div><div class="ttdeci">void endBuildModChain(Context &amp;context)</div><div class="ttdef"><b>Definition:</b> primeChain.cpp:641</div></div>
<div class="ttc" id="aclasshelib_1_1_context_html_ab79e1f941d6043131a14404c68bf538c"><div class="ttname"><a href="classhelib_1_1_context.html#ab79e1f941d6043131a14404c68bf538c">helib::Context::noiseBoundForUniform</a></div><div class="ttdeci">double noiseBoundForUniform(double magBound, long degBound) const</div><div class="ttdef"><b>Definition:</b> Context.h:125</div></div>
<div class="ttc" id="aclasshelib_1_1_context_html_aa2da1bad87f9c90f15b70cb14777685d"><div class="ttname"><a href="classhelib_1_1_context.html#aa2da1bad87f9c90f15b70cb14777685d">helib::Context::ithPrime</a></div><div class="ttdeci">long ithPrime(unsigned long i) const</div><div class="ttdoc">The ith small prime in the modulus chain.</div><div class="ttdef"><b>Definition:</b> Context.h:359</div></div>
<div class="ttc" id="aclasshelib_1_1_context_html_af6b7e88d642f51a00c08263aebaa2e20"><div class="ttname"><a href="classhelib_1_1_context.html#af6b7e88d642f51a00c08263aebaa2e20">helib::Context::rcData</a></div><div class="ttdeci">ThinRecryptData rcData</div><div class="ttdoc">Bootstrapping-related data in the context.</div><div class="ttdef"><b>Definition:</b> Context.h:317</div></div>
<div class="ttc" id="anamespacehelib_html_a3167b996c8b02f9f390d1d9957693b9f"><div class="ttname"><a href="namespacehelib.html#a3167b996c8b02f9f390d1d9957693b9f">helib::writeContextBaseBinary</a></div><div class="ttdeci">void writeContextBaseBinary(std::ostream &amp;str, const Context &amp;context)</div><div class="ttdoc">write [m p r gens ords] data</div><div class="ttdef"><b>Definition:</b> Context.cpp:225</div></div>
<div class="ttc" id="anamespacehelib_html_af68cc874f7e017cd4c35d1ea52739c0f"><div class="ttname"><a href="namespacehelib.html#af68cc874f7e017cd4c35d1ea52739c0f">helib::buildModChain</a></div><div class="ttdeci">void buildModChain(Context &amp;context, long nBits, long nDgts=3, bool willBeBootstrappable=false, long skHwt=0, long resolution=3, long bitsInSpecialPrimes=0)</div><div class="ttdef"><b>Definition:</b> primeChain.cpp:653</div></div>
<div class="ttc" id="aclasshelib_1_1_context_html_acb3ebd14d55203e09b351b88eca17a44"><div class="ttname"><a href="classhelib_1_1_context.html#acb3ebd14d55203e09b351b88eca17a44">helib::Context::allPrimes</a></div><div class="ttdeci">IndexSet allPrimes() const</div><div class="ttdef"><b>Definition:</b> Context.h:339</div></div>
<div class="ttc" id="aclasshelib_1_1_context_html_a26f5e8b08576bf2ab4632bc8234243e2"><div class="ttname"><a href="classhelib_1_1_context.html#a26f5e8b08576bf2ab4632bc8234243e2">helib::Context::pwfl_converter</a></div><div class="ttdeci">std::shared_ptr&lt; const PowerfulDCRT &gt; pwfl_converter</div><div class="ttdef"><b>Definition:</b> Context.h:76</div></div>
<div class="ttc" id="aclasshelib_1_1_index_set_html_a8156f49ca3715bf0cf9c63ac8dc02172"><div class="ttname"><a href="classhelib_1_1_index_set.html#a8156f49ca3715bf0cf9c63ac8dc02172">helib::IndexSet::last</a></div><div class="ttdeci">long last() const</div><div class="ttdoc">Returns the last element, -1 if the set is empty.</div><div class="ttdef"><b>Definition:</b> IndexSet.h:71</div></div>
<div class="ttc" id="aclasshelib_1_1_context_html_aca4f48776f48a323315928889c64f0d1"><div class="ttname"><a href="classhelib_1_1_context.html#aca4f48776f48a323315928889c64f0d1">helib::Context::noiseBoundForHWt</a></div><div class="ttdeci">double noiseBoundForHWt(long hwt, UNUSED long degBound) const</div><div class="ttdef"><b>Definition:</b> Context.h:231</div></div>
<div class="ttc" id="apowerful_8h_html"><div class="ttname"><a href="powerful_8h.html">powerful.h</a></div><div class="ttdoc">The &quot;powerful basis&quot; of a cyclotomic ring.</div></div>
<div class="ttc" id="aclasshelib_1_1_context_html_abb8f32691d102e0390b5770526c8d4fd"><div class="ttname"><a href="classhelib_1_1_context.html#abb8f32691d102e0390b5770526c8d4fd">helib::Context::isBootstrappable</a></div><div class="ttdeci">bool isBootstrappable() const</div><div class="ttdef"><b>Definition:</b> Context.h:335</div></div>
<div class="ttc" id="aclasshelib_1_1_index_set_html_a018572f1e76bc3c9750491f2cf02c7ca"><div class="ttname"><a href="classhelib_1_1_index_set.html#a018572f1e76bc3c9750491f2cf02c7ca">helib::IndexSet::card</a></div><div class="ttdeci">long card() const</div><div class="ttdoc">The cardinality of the set.</div><div class="ttdef"><b>Definition:</b> IndexSet.h:80</div></div>
<div class="ttc" id="anamespacehelib_html_a8425881cdaaef9fade4dd57cc3cf5e8b"><div class="ttname"><a href="namespacehelib.html#a8425881cdaaef9fade4dd57cc3cf5e8b">helib::writeContextBase</a></div><div class="ttdeci">void writeContextBase(std::ostream &amp;s, const Context &amp;context)</div><div class="ttdoc">write [m p r gens ords] data</div><div class="ttdef"><b>Definition:</b> Context.cpp:405</div></div>
<div class="ttc" id="aclasshelib_1_1_logic_error_html"><div class="ttname"><a href="classhelib_1_1_logic_error.html">helib::LogicError</a></div><div class="ttdoc">Inherits from Exception and std::logic_error.</div><div class="ttdef"><b>Definition:</b> exceptions.h:68</div></div>
<div class="ttc" id="aclasshelib_1_1_context_html_a6d1a18803b7a39ff477bf3318aa98be5"><div class="ttname"><a href="classhelib_1_1_context.html#a6d1a18803b7a39ff477bf3318aa98be5">helib::Context::boundForRecryption</a></div><div class="ttdeci">double boundForRecryption(long skHwt=0) const</div><div class="ttdef"><b>Definition:</b> Context.h:267</div></div>
<div class="ttc" id="aclasshelib_1_1_thin_recrypt_data_html_accba45a87da96c0545b19c82d20c2da0"><div class="ttname"><a href="classhelib_1_1_thin_recrypt_data.html#accba45a87da96c0545b19c82d20c2da0">helib::ThinRecryptData::init</a></div><div class="ttdeci">void init(const Context &amp;context, const NTL::Vec&lt; long &gt; &amp;mvec_, bool alsoThick, long t=0, bool build_cache=false, bool minimal=false)</div><div class="ttdoc">Initialize the recryption data in the context.</div><div class="ttdef"><b>Definition:</b> recryption.cpp:771</div></div>
<div class="ttc" id="aclasshelib_1_1_context_html_a40d28a7b77f5735cc6d082452e7126a9"><div class="ttname"><a href="classhelib_1_1_context.html#a40d28a7b77f5735cc6d082452e7126a9">helib::Context::readContextBase</a></div><div class="ttdeci">friend void readContextBase(std::istream &amp;str, unsigned long &amp;m, unsigned long &amp;p, unsigned long &amp;r, std::vector&lt; long &gt; &amp;gens, std::vector&lt; long &gt; &amp;ords)</div><div class="ttdoc">read [m p r] data, needed to construct context</div><div class="ttdef"><b>Definition:</b> Context.cpp:464</div></div>
<div class="ttc" id="aclasshelib_1_1_context_html_a2b87d5f0041ad5abe2bcf358cb818343"><div class="ttname"><a href="classhelib_1_1_context.html#a2b87d5f0041ad5abe2bcf358cb818343">helib::Context::isZeroDivisor</a></div><div class="ttdeci">bool isZeroDivisor(const NTL::ZZ &amp;num) const</div><div class="ttdoc">Is num divisible by any of the primes in the chain?</div><div class="ttdef"><b>Definition:</b> Context.h:371</div></div>
<div class="ttc" id="anamespacehelib_html_acb88b203e4e9aeaf5fe329e7cc276aad"><div class="ttname"><a href="namespacehelib.html#acb88b203e4e9aeaf5fe329e7cc276aad">helib::readContextBaseBinary</a></div><div class="ttdeci">void readContextBaseBinary(std::istream &amp;s, unsigned long &amp;m, unsigned long &amp;p, unsigned long &amp;r, std::vector&lt; long &gt; &amp;gens, std::vector&lt; long &gt; &amp;ords)</div><div class="ttdoc">read [m p r gens ords] data, needed to construct context</div><div class="ttdef"><b>Definition:</b> Context.cpp:254</div></div>
<div class="ttc" id="anamespacehelib_html_a3ba322251033959f95b296f34745836e"><div class="ttname"><a href="namespacehelib.html#a3ba322251033959f95b296f34745836e">helib::activeContext</a></div><div class="ttdeci">Context * activeContext</div><div class="ttdef"><b>Definition:</b> Context.cpp:176</div></div>
<div class="ttc" id="aclasshelib_1_1_moduli_sizes_html_ad621f5c0fa4ce4bf037888eadb7db437"><div class="ttname"><a href="classhelib_1_1_moduli_sizes.html#ad621f5c0fa4ce4bf037888eadb7db437">helib::ModuliSizes::init</a></div><div class="ttdeci">void init(const std::vector&lt; Cmodulus &gt; &amp;chain, const IndexSet &amp;ctxtPrimes, const IndexSet &amp;smallPrimes)</div><div class="ttdoc">initialize helper table for a given chain</div><div class="ttdef"><b>Definition:</b> primeChain.cpp:56</div></div>
<div class="ttc" id="aclasshelib_1_1_recrypt_data_html_a6e9384f58128b7a75b9a1f66842fbb5b"><div class="ttname"><a href="classhelib_1_1_recrypt_data.html#a6e9384f58128b7a75b9a1f66842fbb5b">helib::RecryptData::skHwt</a></div><div class="ttdeci">long skHwt</div><div class="ttdoc">Hamming weight of recryption secret key.</div><div class="ttdef"><b>Definition:</b> recryption.h:49</div></div>
<div class="ttc" id="aclasshelib_1_1_context_html_ad066ba083a3ba9f4b9627fde8bfa17fe"><div class="ttname"><a href="classhelib_1_1_context.html#ad066ba083a3ba9f4b9627fde8bfa17fe">helib::Context::ithModulus</a></div><div class="ttdeci">const Cmodulus &amp; ithModulus(unsigned long i) const</div><div class="ttdoc">Cmodulus object corresponding to ith small prime in the chain.</div><div class="ttdef"><b>Definition:</b> Context.h:365</div></div>
<div class="ttc" id="aclasshelib_1_1_context_html_a93ce4564b2ec97c85c50e732c04a1b22"><div class="ttname"><a href="classhelib_1_1_context.html#a93ce4564b2ec97c85c50e732c04a1b22">helib::Context::noiseBoundForMod</a></div><div class="ttdeci">double noiseBoundForMod(long modulus, long degBound) const</div><div class="ttdef"><b>Definition:</b> Context.h:163</div></div>
<div class="ttc" id="aclasshelib_1_1_p_algebra_html_a3dcfa1c03e7f17674c16e9d25687f87a"><div class="ttname"><a href="classhelib_1_1_p_algebra.html#a3dcfa1c03e7f17674c16e9d25687f87a">helib::PAlgebra::get_cM</a></div><div class="ttdeci">double get_cM() const</div><div class="ttdef"><b>Definition:</b> PAlgebra.h:196</div></div>
<div class="ttc" id="aclasshelib_1_1_context_html_a08ad8299f225b9f8603f8936a98c2453"><div class="ttname"><a href="classhelib_1_1_context.html#a08ad8299f225b9f8603f8936a98c2453">helib::Context::Context</a></div><div class="ttdeci">Context(unsigned long m, unsigned long p, unsigned long r, const std::vector&lt; long &gt; &amp;gens=std::vector&lt; long &gt;(), const std::vector&lt; long &gt; &amp;ords=std::vector&lt; long &gt;())</div><div class="ttdef"><b>Definition:</b> Context.cpp:569</div></div>
<div class="ttc" id="aclasshelib_1_1_context_html_a3a9a7a348aecd453c92d1c077a9af03d"><div class="ttname"><a href="classhelib_1_1_context.html#a3a9a7a348aecd453c92d1c077a9af03d">helib::Context::writeContextBase</a></div><div class="ttdeci">friend void writeContextBase(std::ostream &amp;str, const Context &amp;context)</div><div class="ttdoc">write [m p r] data</div><div class="ttdef"><b>Definition:</b> Context.cpp:405</div></div>
<div class="ttc" id="aclasshelib_1_1_context_html_aa10cb4160e67f8fc94dbbcd14be3a7c5"><div class="ttname"><a href="classhelib_1_1_context.html#aa10cb4160e67f8fc94dbbcd14be3a7c5">helib::Context::productOfPrimes</a></div><div class="ttdeci">NTL::ZZ productOfPrimes(const IndexSet &amp;s) const</div><div class="ttdef"><b>Definition:</b> Context.h:391</div></div>
<div class="ttc" id="aclasshelib_1_1_p_algebra_html"><div class="ttname"><a href="classhelib_1_1_p_algebra.html">helib::PAlgebra</a></div><div class="ttdoc">The structure of (Z/mZ)* /(p)</div><div class="ttdef"><b>Definition:</b> PAlgebra.h:77</div></div>
<div class="ttc" id="anamespacehelib_html_a1f9bc09cb4de5422bb79e9c4d67db80a"><div class="ttname"><a href="namespacehelib.html#a1f9bc09cb4de5422bb79e9c4d67db80a">helib::writeContextBinary</a></div><div class="ttdeci">void writeContextBinary(std::ostream &amp;str, const Context &amp;context)</div><div class="ttdef"><b>Definition:</b> Context.cpp:284</div></div>
<div class="ttc" id="aclasshelib_1_1_context_html_a9a8689e8a591a15fdf4f1b5eb7b0b80c"><div class="ttname"><a href="classhelib_1_1_context.html#a9a8689e8a591a15fdf4f1b5eb7b0b80c">helib::Context::alMod</a></div><div class="ttdeci">PAlgebraMod alMod</div><div class="ttdoc">The structure of Z[X]/(Phi_m(X),p^r)</div><div class="ttdef"><b>Definition:</b> Context.h:71</div></div>
<div class="ttc" id="a_test__approx_nums_8cpp_html_ab3f078684998b83967d507d0f453f454"><div class="ttname"><a href="_test__approx_nums_8cpp.html#ab3f078684998b83967d507d0f453f454">verbose</a></div><div class="ttdeci">bool verbose</div><div class="ttdef"><b>Definition:</b> Test_approxNums.cpp:24</div></div>
<div class="ttc" id="aclasshelib_1_1_index_set_html"><div class="ttname"><a href="classhelib_1_1_index_set.html">helib::IndexSet</a></div><div class="ttdoc">A dynamic set of non-negative integers.</div><div class="ttdef"><b>Definition:</b> IndexSet.h:31</div></div>
<div class="ttc" id="aclasshelib_1_1_context_html_a9d52169353df3e667210c59c1643e316"><div class="ttname"><a href="classhelib_1_1_context.html#a9d52169353df3e667210c59c1643e316">helib::Context::smallPrimes</a></div><div class="ttdeci">IndexSet smallPrimes</div><div class="ttdef"><b>Definition:</b> Context.h:290</div></div>
<div class="ttc" id="aclasshelib_1_1_context_html_ac2b4477cbc59e744b735544b60bb4f87"><div class="ttname"><a href="classhelib_1_1_context.html#ac2b4477cbc59e744b735544b60bb4f87">helib::Context::noiseBoundForGaussian</a></div><div class="ttdeci">double noiseBoundForGaussian(double sigma, long degBound) const</div><div class="ttdef"><b>Definition:</b> Context.h:186</div></div>
<div class="ttc" id="aclasshelib_1_1_context_html_abfe778f83df73ee943f9fc25741efa2e"><div class="ttname"><a href="classhelib_1_1_context.html#abfe778f83df73ee943f9fc25741efa2e">helib::Context::getCtxtPrimes</a></div><div class="ttdeci">IndexSet getCtxtPrimes(long nprimes) const</div><div class="ttdef"><b>Definition:</b> Context.h:345</div></div>
<div class="ttc" id="anamespacehelib_html_ab7b88eb3fd0aa4821cb6700fa65ecee2"><div class="ttname"><a href="namespacehelib.html#ab7b88eb3fd0aa4821cb6700fa65ecee2">helib::readContextBase</a></div><div class="ttdeci">void readContextBase(std::istream &amp;s, unsigned long &amp;m, unsigned long &amp;p, unsigned long &amp;r, std::vector&lt; long &gt; &amp;gens, std::vector&lt; long &gt; &amp;ords)</div><div class="ttdoc">read [m p r gens ords] data, needed to construct context</div><div class="ttdef"><b>Definition:</b> Context.cpp:464</div></div>
<div class="ttc" id="a_p_algebra_8h_html"><div class="ttname"><a href="_p_algebra_8h.html">PAlgebra.h</a></div><div class="ttdoc">Declarations of the classes PAlgebra.</div></div>
<div class="ttc" id="aclasshelib_1_1_recrypt_data_html_aa33d0f2a11a834d4c4eda0cd4513b3c0"><div class="ttname"><a href="classhelib_1_1_recrypt_data.html#aa33d0f2a11a834d4c4eda0cd4513b3c0">helib::RecryptData::alMod</a></div><div class="ttdeci">std::shared_ptr&lt; const PAlgebraMod &gt; alMod</div><div class="ttdoc">for plaintext space p^{e-e'+r}</div><div class="ttdef"><b>Definition:</b> recryption.h:52</div></div>
<div class="ttc" id="aclasshelib_1_1_context_html_a3feef5466cf8ed4878446d0142ac0be4"><div class="ttname"><a href="classhelib_1_1_context.html#a3feef5466cf8ed4878446d0142ac0be4">helib::Context::BPL</a></div><div class="ttdeci">long BPL() const</div><div class="ttdef"><b>Definition:</b> Context.h:353</div></div>
<div class="ttc" id="aclasshelib_1_1_context_html_ae6f113ef16d2e6c1ca451411e34eed42"><div class="ttname"><a href="classhelib_1_1_context.html#ae6f113ef16d2e6c1ca451411e34eed42">helib::Context::operator==</a></div><div class="ttdeci">bool operator==(const Context &amp;other) const</div><div class="ttdef"><b>Definition:</b> Context.cpp:185</div></div>
<div class="ttc" id="aclasshelib_1_1_context_html_a4237638ccaec9233a0c7edaf334343b2"><div class="ttname"><a href="classhelib_1_1_context.html#a4237638ccaec9233a0c7edaf334343b2">helib::Context::specialPrimes</a></div><div class="ttdeci">IndexSet specialPrimes</div><div class="ttdef"><b>Definition:</b> Context.h:285</div></div>
<div class="ttc" id="aclasshelib_1_1_cmodulus_html"><div class="ttname"><a href="classhelib_1_1_cmodulus.html">helib::Cmodulus</a></div><div class="ttdoc">Provides FFT and iFFT routines modulo a single-precision prime.</div><div class="ttdef"><b>Definition:</b> CModulus.h:43</div></div>
<div class="ttc" id="aapi_attributes_8h_html_addf5ec070e9499d36b7f2009ce736076"><div class="ttname"><a href="api_attributes_8h.html#addf5ec070e9499d36b7f2009ce736076">UNUSED</a></div><div class="ttdeci">#define UNUSED</div><div class="ttdef"><b>Definition:</b> apiAttributes.h:31</div></div>
<div class="ttc" id="aclasshelib_1_1_context_html_a552e300656dfae6eaacace769c03655a"><div class="ttname"><a href="classhelib_1_1_context.html#a552e300656dfae6eaacace769c03655a">helib::Context::numPrimes</a></div><div class="ttdeci">long numPrimes() const</div><div class="ttdoc">Total number of small prime in the chain.</div><div class="ttdef"><b>Definition:</b> Context.h:368</div></div>
<div class="ttc" id="aclasshelib_1_1_context_html_a065f668db1a4712692fdd2ea9c70dc47"><div class="ttname"><a href="classhelib_1_1_context.html#a065f668db1a4712692fdd2ea9c70dc47">helib::Context::securityLevel</a></div><div class="ttdeci">double securityLevel() const</div><div class="ttdoc">An estimate for the security-level.</div><div class="ttdef"><b>Definition:</b> Context.h:416</div></div>
<div class="ttc" id="aclasshelib_1_1_context_html_aa65a6f2210ee990f8f3d4cbc60a6060a"><div class="ttname"><a href="classhelib_1_1_context.html#aa65a6f2210ee990f8f3d4cbc60a6060a">helib::Context::AddSmallPrime</a></div><div class="ttdeci">void AddSmallPrime(long q)</div><div class="ttdoc">Just add the given prime to the chain.</div><div class="ttdef"><b>Definition:</b> primeChain.cpp:378</div></div>
<div class="ttc" id="aclasshelib_1_1_context_html_acc2c4b8400734e630cebe544fbf01cc1"><div class="ttname"><a href="classhelib_1_1_context.html#acc2c4b8400734e630cebe544fbf01cc1">helib::Context::AddSpecialPrime</a></div><div class="ttdeci">void AddSpecialPrime(long q)</div><div class="ttdef"><b>Definition:</b> primeChain.cpp:394</div></div>
<div class="ttc" id="a_index_set_8h_html"><div class="ttname"><a href="_index_set_8h.html">IndexSet.h</a></div><div class="ttdoc">A dynamic set of integers.</div></div>
<div class="ttc" id="anamespacehelib_html_abbf9f5de032fca82af2ce94a97041bc6"><div class="ttname"><a href="namespacehelib.html#abbf9f5de032fca82af2ce94a97041bc6">helib::FindM</a></div><div class="ttdeci">long FindM(long k, long nBits, long c, long p, long d, long s, long chosen_m, bool verbose=false)</div><div class="ttdoc">Returns smallest parameter m satisfying various constraints:</div><div class="ttdef"><b>Definition:</b> Context.cpp:24</div></div>
<div class="ttc" id="aclasshelib_1_1_context_html_a237f432913ec39edc41af03384d4475d"><div class="ttname"><a href="classhelib_1_1_context.html#a237f432913ec39edc41af03384d4475d">helib::Context::logOfProduct</a></div><div class="ttdeci">double logOfProduct(const IndexSet &amp;s) const</div><div class="ttdoc">Returns the natural logarithm of productOfPrimes(s)</div><div class="ttdef"><b>Definition:</b> Context.h:404</div></div>
<div class="ttc" id="aclasshelib_1_1_context_html_a3f25fcb8f7047c32e2929d9ffbf4ac11"><div class="ttname"><a href="classhelib_1_1_context.html#a3f25fcb8f7047c32e2929d9ffbf4ac11">helib::Context::operator&lt;&lt;</a></div><div class="ttdeci">friend std::ostream &amp; operator&lt;&lt;(std::ostream &amp;str, const Context &amp;context)</div><div class="ttdoc">Write all other data.</div><div class="ttdef"><b>Definition:</b> Context.cpp:426</div></div>
<div class="ttc" id="anamespacehelib_html_a4a07fadbe58c0bf5c4be26d9bb245755"><div class="ttname"><a href="namespacehelib.html#a4a07fadbe58c0bf5c4be26d9bb245755">helib::readContextBinary</a></div><div class="ttdeci">void readContextBinary(std::istream &amp;str, Context &amp;context)</div><div class="ttdef"><b>Definition:</b> Context.cpp:332</div></div>
<div class="ttc" id="aclasshelib_1_1_p_algebra_html_afb8bd85921189335d6d6f2fe30011907"><div class="ttname"><a href="classhelib_1_1_p_algebra.html#afb8bd85921189335d6d6f2fe30011907">helib::PAlgebra::getNFactors</a></div><div class="ttdeci">long getNFactors() const</div><div class="ttdoc">The number of distinct prime factors of m.</div><div class="ttdef"><b>Definition:</b> PAlgebra.h:174</div></div>
<div class="ttc" id="anamespacehelib_html"><div class="ttname"><a href="namespacehelib.html">helib</a></div><div class="ttdef"><b>Definition:</b> apiAttributes.h:21</div></div>
<div class="ttc" id="aclasshelib_1_1_context_html_ad1e445830c6007a7f725e100f19dfe6a"><div class="ttname"><a href="classhelib_1_1_context.html#ad1e445830c6007a7f725e100f19dfe6a">helib::Context::readContextBinary</a></div><div class="ttdeci">friend void readContextBinary(std::istream &amp;str, Context &amp;context)</div><div class="ttdef"><b>Definition:</b> Context.cpp:332</div></div>
<div class="ttc" id="aapi_attributes_8h_html"><div class="ttname"><a href="api_attributes_8h.html">apiAttributes.h</a></div></div>
<div class="ttc" id="aclasshelib_1_1_index_set_html_a30a96e32a1bec249fb56f83bbb6f4afa"><div class="ttname"><a href="classhelib_1_1_index_set.html#a30a96e32a1bec249fb56f83bbb6f4afa">helib::IndexSet::first</a></div><div class="ttdeci">long first() const</div><div class="ttdoc">Returns the first element, 0 if the set is empty.</div><div class="ttdef"><b>Definition:</b> IndexSet.h:68</div></div>
<div class="ttc" id="aclasshelib_1_1_context_html_ab25e83e61a64ed721a1b710a3b2df82d"><div class="ttname"><a href="classhelib_1_1_context.html#ab25e83e61a64ed721a1b710a3b2df82d">helib::Context::noiseBoundForUniform</a></div><div class="ttdeci">NTL::xdouble noiseBoundForUniform(NTL::xdouble magBound, long degBound) const</div><div class="ttdef"><b>Definition:</b> Context.h:130</div></div>
<div class="ttc" id="aclasshelib_1_1_context_html_afc6a3c91d2488abe71e82849653b2c40"><div class="ttname"><a href="classhelib_1_1_context.html#afc6a3c91d2488abe71e82849653b2c40">helib::Context::productOfPrimes</a></div><div class="ttdeci">void productOfPrimes(NTL::ZZ &amp;p, const IndexSet &amp;s) const</div><div class="ttdoc">The product of all the primes in the given set.</div><div class="ttdef"><b>Definition:</b> Context.cpp:178</div></div>
<div class="ttc" id="aclasshelib_1_1_context_html_a86b3d6e90031da9bc9cef6f46e9e9bda"><div class="ttname"><a href="classhelib_1_1_context.html#a86b3d6e90031da9bc9cef6f46e9e9bda">helib::Context::scale</a></div><div class="ttdeci">double scale</div><div class="ttdef"><b>Definition:</b> Context.h:88</div></div>
<div class="ttc" id="aclasshelib_1_1_context_html_abd63a1dac045b9e1225e9b42b7506e64"><div class="ttname"><a href="classhelib_1_1_context.html#abd63a1dac045b9e1225e9b42b7506e64">helib::Context::logOfPrime</a></div><div class="ttdeci">double logOfPrime(unsigned long i) const</div><div class="ttdoc">Returns the natural logarithm of the ith prime.</div><div class="ttdef"><b>Definition:</b> Context.h:401</div></div>
<div class="ttc" id="aclasshelib_1_1_moduli_sizes_html"><div class="ttname"><a href="classhelib_1_1_moduli_sizes.html">helib::ModuliSizes</a></div><div class="ttdoc">A helper class to map required modulo-sizes to primeSets.</div><div class="ttdef"><b>Definition:</b> primeChain.h:27</div></div>
<div class="ttc" id="aclasshelib_1_1_context_html_a1eae4b3032d34226da9b04897b414179"><div class="ttname"><a href="classhelib_1_1_context.html#a1eae4b3032d34226da9b04897b414179">helib::Context::noiseBoundForSmall</a></div><div class="ttdeci">double noiseBoundForSmall(double prob, long degBound) const</div><div class="ttdef"><b>Definition:</b> Context.h:208</div></div>
<div class="ttc" id="aprime_chain_8h_html"><div class="ttname"><a href="prime_chain_8h.html">primeChain.h</a></div><div class="ttdoc">handling the chain of moduli</div></div>
<div class="ttc" id="aclasshelib_1_1_p_algebra_html_a4422e1911052282a6881fa97ae5061dd"><div class="ttname"><a href="classhelib_1_1_p_algebra.html#a4422e1911052282a6881fa97ae5061dd">helib::PAlgebra::getPhiM</a></div><div class="ttdeci">long getPhiM() const</div><div class="ttdoc">Returns phi(m)</div><div class="ttdef"><b>Definition:</b> PAlgebra.h:168</div></div>
<div class="ttc" id="aclasshelib_1_1_context_html_a30037bfeed9ef5a4282e10b92c149801"><div class="ttname"><a href="classhelib_1_1_context.html#a30037bfeed9ef5a4282e10b92c149801">helib::Context::stdDevForRecryption</a></div><div class="ttdeci">double stdDevForRecryption(long skHwt=0) const</div><div class="ttdoc">NOTE: this is a bit heuristic. See design document for details.</div><div class="ttdef"><b>Definition:</b> Context.h:250</div></div>
<div class="ttc" id="aclasshelib_1_1_context_html"><div class="ttname"><a href="classhelib_1_1_context.html">helib::Context</a></div><div class="ttdoc">Maintaining the parameters.</div><div class="ttdef"><b>Definition:</b> Context.h:58</div></div>
<div class="ttc" id="aclasshelib_1_1_context_html_ad2eaf7ce504e725b8e6be631ff276efc"><div class="ttname"><a href="classhelib_1_1_context.html#ad2eaf7ce504e725b8e6be631ff276efc">helib::Context::stdev</a></div><div class="ttdeci">NTL::xdouble stdev</div><div class="ttdoc">sqrt(variance) of the LWE error (default=3.2)</div><div class="ttdef"><b>Definition:</b> Context.h:85</div></div>
<div class="ttc" id="aclasshelib_1_1_p_algebra_mod_html"><div class="ttname"><a href="classhelib_1_1_p_algebra_mod.html">helib::PAlgebraMod</a></div><div class="ttdoc">The structure of Z[X]/(Phi_m(X), p)</div><div class="ttdef"><b>Definition:</b> PAlgebra.h:798</div></div>
<div class="ttc" id="aclasshelib_1_1_context_html_a9dea4625a64c673ad3147bf18a1d231f"><div class="ttname"><a href="classhelib_1_1_context.html#a9dea4625a64c673ad3147bf18a1d231f">helib::Context::inChain</a></div><div class="ttdeci">bool inChain(long p) const</div><div class="ttdoc">Is p already in the chain?</div><div class="ttdef"><b>Definition:</b> Context.h:380</div></div>
<div class="ttc" id="anamespacehelib_html_adcfd34a416649164e3b01c4af1c8654e"><div class="ttname"><a href="namespacehelib.html#adcfd34a416649164e3b01c4af1c8654e">helib::buildContextFromAscii</a></div><div class="ttdeci">std::unique_ptr&lt; Context &gt; buildContextFromAscii(std::istream &amp;str)</div><div class="ttdef"><b>Definition:</b> Context.cpp:480</div></div>
<div class="ttc" id="aclasshelib_1_1_context_html_a717438f68d2a050214ee4a8a933a7bba"><div class="ttname"><a href="classhelib_1_1_context.html#a717438f68d2a050214ee4a8a933a7bba">helib::Context::operator&gt;&gt;</a></div><div class="ttdeci">friend std::istream &amp; operator&gt;&gt;(std::istream &amp;str, Context &amp;context)</div><div class="ttdoc">read all other data associated with context</div><div class="ttdef"><b>Definition:</b> Context.cpp:488</div></div>
<div class="ttc" id="anamespacehelib_html_a4036006b2d0e378ce2aa90a5332a8d73"><div class="ttname"><a href="namespacehelib.html#a4036006b2d0e378ce2aa90a5332a8d73">helib::buildContextFromBinary</a></div><div class="ttdeci">std::unique_ptr&lt; Context &gt; buildContextFromBinary(std::istream &amp;str)</div><div class="ttdef"><b>Definition:</b> Context.cpp:276</div></div>
<div class="ttc" id="anamespacehelib_html_ad92538fab792f75e009a2330c365637d"><div class="ttname"><a href="namespacehelib.html#ad92538fab792f75e009a2330c365637d">helib::fsquare</a></div><div class="ttdeci">double fsquare(double x)</div><div class="ttdoc">Return the square of a number as a double.</div><div class="ttdef"><b>Definition:</b> NumbTh.h:150</div></div>
<div class="ttc" id="aclasshelib_1_1_context_html_a83165f2f0d0a6dd8bb3c3f227e7da1a3"><div class="ttname"><a href="classhelib_1_1_context.html#a83165f2f0d0a6dd8bb3c3f227e7da1a3">helib::Context::writeContextBinary</a></div><div class="ttdeci">friend void writeContextBinary(std::ostream &amp;str, const Context &amp;context)</div><div class="ttdef"><b>Definition:</b> Context.cpp:284</div></div>
<div class="ttc" id="aclasshelib_1_1_context_html_a1a9dbcc75c6cf5116b8114dccc1f1ab7"><div class="ttname"><a href="classhelib_1_1_context.html#a1a9dbcc75c6cf5116b8114dccc1f1ab7">helib::Context::slotRing</a></div><div class="ttdeci">std::shared_ptr&lt; PolyModRing &gt; slotRing</div><div class="ttdoc">The structure of a single slot of the plaintext space.</div><div class="ttdef"><b>Definition:</b> Context.h:82</div></div>
<div class="ttc" id="aclasshelib_1_1_context_html_a3d08d9248d0d3165fa5914b95bd60fdf"><div class="ttname"><a href="classhelib_1_1_context.html#a3d08d9248d0d3165fa5914b95bd60fdf">helib::Context::operator!=</a></div><div class="ttdeci">bool operator!=(const Context &amp;other) const</div><div class="ttdef"><b>Definition:</b> Context.h:356</div></div>
<div class="ttc" id="aclasshelib_1_1_context_html_af915dcf0e80c5014ef2dc6911891262d"><div class="ttname"><a href="classhelib_1_1_context.html#af915dcf0e80c5014ef2dc6911891262d">helib::Context::AddCtxtPrime</a></div><div class="ttdeci">void AddCtxtPrime(long q)</div><div class="ttdef"><b>Definition:</b> primeChain.cpp:386</div></div>
<div class="ttc" id="aclasshelib_1_1_context_html_aeb97afc7e74b0b7522c4168d8db2b374"><div class="ttname"><a href="classhelib_1_1_context.html#aeb97afc7e74b0b7522c4168d8db2b374">helib::Context::makeBootstrappable</a></div><div class="ttdeci">void makeBootstrappable(const NTL::Vec&lt; long &gt; &amp;mvec, long skWht=0, bool build_cache=false, bool alsoThick=true)</div><div class="ttdef"><b>Definition:</b> Context.h:327</div></div>
<div class="ttc" id="arecryption_8h_html"><div class="ttname"><a href="recryption_8h.html">recryption.h</a></div><div class="ttdoc">Define some data structures to hold recryption data.</div></div>
<div class="ttc" id="anamespacehelib_html_a5dcff6470686ad80a2319fa1652ac1e3"><div class="ttname"><a href="namespacehelib.html#a5dcff6470686ad80a2319fa1652ac1e3">helib::range</a></div><div class="ttdeci">general_range&lt; long &gt; range(long n)</div><div class="ttdef"><b>Definition:</b> range.h:57</div></div>
<div class="ttc" id="aclasshelib_1_1_context_html_a09e894a14a98620a7f129c992468072f"><div class="ttname"><a href="classhelib_1_1_context.html#a09e894a14a98620a7f129c992468072f">helib::Context::ctxtPrimes</a></div><div class="ttdeci">IndexSet ctxtPrimes</div><div class="ttdef"><b>Definition:</b> Context.h:280</div></div>
<div class="ttc" id="a_c_modulus_8h_html"><div class="ttname"><a href="_c_modulus_8h.html">CModulus.h</a></div><div class="ttdoc">Supports forward and backward length-m FFT transformations.</div></div>
<div class="ttc" id="aclasshelib_1_1_context_html_a8f143c4d8e8fde51e2fce121a904eb0a"><div class="ttname"><a href="classhelib_1_1_context.html#a8f143c4d8e8fde51e2fce121a904eb0a">helib::Context::fullPrimes</a></div><div class="ttdeci">IndexSet fullPrimes() const</div><div class="ttdef"><b>Definition:</b> Context.h:337</div></div>
<div class="ttc" id="aclasshelib_1_1_context_html_ab261446cf0a635a7bf1edf081df48d81"><div class="ttname"><a href="classhelib_1_1_context.html#ab261446cf0a635a7bf1edf081df48d81">helib::Context::zMStar</a></div><div class="ttdeci">PAlgebra zMStar</div><div class="ttdoc">The structure of Zm*.</div><div class="ttdef"><b>Definition:</b> Context.h:68</div></div>
<div class="ttc" id="aclasshelib_1_1_context_html_a221facd004b3ace6f11367d6766f9b78"><div class="ttname"><a href="classhelib_1_1_context.html#a221facd004b3ace6f11367d6766f9b78">helib::Context::digits</a></div><div class="ttdeci">std::vector&lt; IndexSet &gt; digits</div><div class="ttdoc">The set of primes for the digits.</div><div class="ttdef"><b>Definition:</b> Context.h:313</div></div>
<div class="ttc" id="aclasshelib_1_1_context_html_a8319e609dbde819ac81130b035711fee"><div class="ttname"><a href="classhelib_1_1_context.html#a8319e609dbde819ac81130b035711fee">helib::Context::ea</a></div><div class="ttdeci">std::shared_ptr&lt; const EncryptedArray &gt; ea</div><div class="ttdoc">A default EncryptedArray.</div><div class="ttdef"><b>Definition:</b> Context.h:74</div></div>
<!-- HTML footer for doxygen 1.8.8-->
<!-- start footer part -->
</div>
</div>
</div>
</div>
</div>
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.18
</small></address>
</body>
        <script type="text/javascript" src="doxy-boot.js"></script>
</html>
